If you are looking for a few examples on how to use PowerShell Copy-Item, This tutorial explains, how we can use Copy-Item in PowerShell. Also, we will discuss the below points:
PowerShell Copy-Item | What is copy-item PowerShell?
We can use Copy-Item to copy any item from one Directory to another. The command will not cut or Detelet the item, it only copies the item from one location to another location. we just need to pass the new name in the Source and Destination parameter in the PowerShell copy-item command.
Example-1:
In the first example, we will see how to copy a file from one location to another location using Copy-Item. Source = “D:\Source\Test1.txt” Destination = “D:\Tech99\Destination”, When you select Source file so we need to select a specific file to a folder and when we can see in below example we only give the destination location.
You can see the file has been copied to the destination location.
Copy-Item "D:\Source\test1.txt" -Destination "D:\Tech99\Destination"
Example-2:
In the next example, we will see how to copy all files at a time from one location to another location. suppose we have a few different types of files in the Source folder, By using the PowerShell Copy-Item cmd we will copy all the files from the source folder to the destination folder but the difference is after Copy-Item “D:\Source\*” we can \* it means what ever item is there in that source folder copy all the item. This is how we can copy all files from one location to another location using Copy-Item PowerShell command.
Copy-Item "D:\Source\*" -Destination "D:\Tech99\Destination"
PowerShell Copy Item recurse subfolders |How do I copy an item in PowerShell?
Now, let us see how to copy item recurse subfolders in PowerShell.In this example Source folder, I have a sub folder which has a few documents. When I run the below command, it will simply create the folder but it did not copy the documents that are presented in the sub folder.
Copy-Item "D:\Source*" -Destination "D:\Tech99\Destination"
In fact, if the subfolder has an extra nested subfolder, it’s not going to create the nested subfolder while you run the Copy-Item PowerShell cmdlet.To copy items recursively, we want to apply the -Recurse parameter with the Copy-Item PowerShell cmdlet. The entire PowerShell cmdlets look like below:
Copy-Item "D:\Source*" -Destination "D:\Tech99\Destination" -Recurse
Once you run the above command, you could see it create the subf older along with nested sub folders and documents to the destination folder. This is an instance of PowerShell Copy-Item recurse subfolders.
How do I copy an item in PowerShell?
How do I copy a folder from a PowerShell script?
How do I copy files from one directory to another in PowerShell?
How do I copy multiple files in PowerShell?
What is copy-item PowerShell?
How do you copy in PowerShell?
How do I copy files and folders in PowerShell?
How do I force copy in PowerShell?