Home/PowerShell, Powershell demo/How to move files from one location to another location using PowerShell

How to move files from one location to another location using PowerShell

In this article, Let I show you how to move files from one location to another location using PowerShell script. The Move-Item cmdlet moves an item, including its properties, contents, and child items, from one location to another location. The locations must be supported by the same provider.

Move-Item : Cannot create a file when that file already exists.

Example:1 Moving single files/folders

In the PowerShell window, type the command below and press ENTER. After the –path parameter,type the path of the file on your local PC that you want to copy, and after the –destination parameter, type the path of the destination folder. In the example below, I’m moving a file called URL_List.txt from the Source File Path folder to Destination File Path folder.

OR we can directly mention the path of files location without -path Keyword

Example:2 Moving all the item which created today.

From below code, we getting all files and folder which created today and move from “Source File Path” folder to “Destination File Path” folder.

Also, by default, Get-ChildItem does not move hidden files. To move hidden files, use the Force parameter with Get-ChildItem.

Example:3 Moving the files based on File Type (extension)

I had created $_FileType array which containing the list of file types that need to move. After execution, all .html and .txt files will move from source to destination folder. Please refer the snap shots to under stand the before and after the script execution

OUTPUT:

Before Execution : Source Folder/Destination Folder

After Execution : Source Folder/Destination Folder

 

What do you think?

I hope you have idea of how to move the files from one location to another location using Powershell script. I would like to have feedback from my posts readers. Your valuable feedback, question, or comments about this article are always welcome.

 

 

Leave a Reply