In Windows, files can be transferred from one folder to any other folder by drag and drop or by cut and paste options. However, using PowerShell, you can perform the same operation with the Move-Item command within a few seconds.
This tutorial will explain how to move files or folders using PowerShell with detailed examples.
How to Move a File Using PowerShell?
In PowerShell, the Move-Item command is utilized for moving files across the system, including their contents, properties, and child items. It can also be used for relocating files based on the added condition.
To move the file by using the Move-Item cmdlet, follow the below syntax:
Here, the -Path option refers to the source path of the file, and -Destination option indicates the required destination location.
Let’s check out some examples related to moving files using the PowerShell Move-Item command.
How to Move a Single File Using PowerShell?
In this example, we will try to move a text file named Powershell to the Test folder that exists at the same location:
To do so, we will execute the following PowerShell Move-Item cmdlet and specify the source and destination paths:
The given output indicates that we have successfully moved the Powershell.txt file to the Test folder:
Now, let’s head towards the next section.
How to Move Multiple Files Using PowerShell?
In this example, we will move multiple files from one folder to another. Here, we have a Test folder that contains four text files and two MS word documents:
We want to move all of the four text files from Test to the New folder:
For this purpose, we will execute the following Move-Item command and specify the source and destination path in it:
Note: Asterix (*) sign is used with the extension of a file for selecting collectively the same format files. So, the given source path will select all files with the .txt extension in the above command.
After executing the above cmdlet, all text files from the “Test” folder will be moved to the folder named “New folder”:
As you can see, the Test Folder now has only word documents. All text files are successfully moved to the destination folder:
We have provided all necessary information related to moving files or folders in PowerShell.
The Move-Item cmdlet is used to move single and multiple files using PowerShell by specifying the source and destination path. Its syntax is given as Move-Item [-Path] <sourcepath> [-Destination] <destinationpath>. The source path indicates where the file exists, and the destination path is the path where the file should be moved. This tutorial explained the procedure for moving files or folders using PowerShell with examples.