Powershell - Copy File



Cmdlet

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 D:\Temp\Test Folder\Test File.txt to D:\Temp\Test Folder1

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 Test File1.txt in Test Folder1 with content of Test File.txt. Test Folder1 folder should be present before running this command.

Example 2

In this example, we'll copy all text file recursively D:\Temp\Test Folder to D:\Temp\Test Folder1

Type the following command in PowerShell ISE Console

Copy-Item -Filter *.txt -Path 'D:\temp\Test Folder' -Recurse -Destination 'D:\temp\Test Folder1'

You can see the content of Test Folder1 in Windows Explorer where it contains both the Test Folder and only text based file(s).

powershell_files_folders.htm
Advertisements