0
0
PowershellHow-ToBeginner · 3 min read

How to Move File in PowerShell: Simple Guide

Use the Move-Item cmdlet in PowerShell to move a file from one location to another. Specify the source file path with -Path and the destination folder or file path with -Destination.
📐

Syntax

The basic syntax of the Move-Item cmdlet is:

  • -Path: The file or folder you want to move.
  • -Destination: The new location or name for the file or folder.

You can also use wildcards in the -Path to move multiple files.

powershell
Move-Item -Path <source> -Destination <destination>
💻

Example

This example moves a file named example.txt from the current folder to a folder named Archive:

powershell
Move-Item -Path .\example.txt -Destination .\Archive\
⚠️

Common Pitfalls

Common mistakes when moving files in PowerShell include:

  • Using incorrect paths or forgetting to escape backslashes.
  • Trying to move a file to a destination that does not exist.
  • Not having permission to write to the destination folder.
  • Overwriting files unintentionally without confirmation.

Always verify paths and permissions before running the command.

powershell
## Wrong: Destination folder does not exist
Move-Item -Path .\file.txt -Destination .\NonExistentFolder\

## Right: Create folder first, then move
New-Item -ItemType Directory -Path .\NonExistentFolder -Force
Move-Item -Path .\file.txt -Destination .\NonExistentFolder\
📊

Quick Reference

ParameterDescription
-PathSpecifies the file or folder to move
-DestinationSpecifies the new location or name
-ForceOverwrites read-only files or hidden files
-WhatIfShows what would happen without making changes
-ConfirmPrompts for confirmation before moving

Key Takeaways

Use Move-Item with -Path and -Destination to move files in PowerShell.
Ensure the destination folder exists before moving files.
Check permissions to avoid errors when moving files.
Use -WhatIf to preview the move operation safely.
Be careful to avoid overwriting files unintentionally.