Cmdlet
Contents
hide
Copy-Item cmdlet is used to copy a file by passing the path of the file to be copied and destination path where the file is to be copied.
Example 1
In this example, we’ll copy a folder from D:\Temp\Test Folder\Test1.txt to D:\Temp\Test2
Type the following command in PowerShell ISE Console
Copy-Item 'D:\temp\Test Folder\Test File.txt' 'D:\temp\Test Folder1\Test File1.txt'
You can see the Test1.txt in Test1 with content of Test2.txt. Test1 folder should be present before running this command.
Example 2
In this below example, we will copy all text file recursively from D:\Temp\Test1 to D:\Temp\Test2
Type the following command in PowerShell ISE Console
Copy-Item -Filter *.txt -Path 'D:\temp\Test Folderabc' -Recurse -Destination 'D:\temp\Test Folder123'
we can see the content of Test Folder123 in Windows Explorer where it contains both the Test Folder and only text based file(s).