Powershell

How to Use the Move-Item Cmdlet in PowerShell?

In PowerShell, the “Move-Item” cmdlet helps in moving an item or items from one folder to another. In simple words, it is a dedicated cmdlet for moving items in PowerShell. Moreover, it can also help move a directory or subdirectory from one specified folder location to another. Alongside moving files or folders it can also move child items, contents, and properties.

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:

Move-Item -Path C:\Docs\New.txt -Destination C:\New\File.txt

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:

Move-Item -Path C:\Docs -Destination C:\New

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:

Move-Item -Path C:\Docs\*.txt -Destination C:\New

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.

About the author

Muhammad Farhan

I am a Computer Science graduate and now a technical writer who loves to provide the easiest solutions to the most difficult problems related to Windows, Linux, and Web designing. My love for Computer Science emerges every day because of its ease in our everyday life.