In this write-up, the “Move-Item” cmdlet will be explained in detail.
How to Use the Move-Item Cmdlet in PowerShell?
As described above, the “Move-Item” cmdlet is responsible for moving files or folders from one place to another.
Example 1: Use the “Move-Item” Cmdlet to Rename and Move a Single File
Execute the provided command to move a file to another folder:
In the above-illustrated command:
- First, specify the “Move-Item” cmdlet along with the “-Path” parameter having the location path, filename, and extension specified.
- After that, define the “-Destination” parameter. Then, assign the target path along with the file name and extension:
Example 2: Use the “Move-Item” Cmdlet to Move a Directory and its Contents to Another Directory
To move a folder along with its contents, first, specify the directory which needs to be moved with the help of the “-Path” parameter and then assign the target directory to the “-Destination” parameter:
Example 3: Use the “Move-Item” Cmdlet to Move all Files of a Specified Extension
This demonstration will move all the files having a specific extension:
In the above-stated command:
- After specifying the “Move-Item” cmdlet, define the “-Path” parameter and provide the file address to be copied along with the “*.txt” extension.
- Then add the “*” wildcard along with the file extension that will select all the files from the specified directory having the “.txt” extension.
- Lastly, use the “-Destination” parameter and assign the target path:
That was all about using the “Move-Item” cmdlet in PowerShell.
Conclusion
The cmdlet “Move-Item” is used to move items including files or folders from one folder to the other in PowerShell. Moreover, it moves the child items, properties, and contents associated with files or folders. This blog has elaborated on the “Move-Item” cmdlet in detail.