PoshTip #17 – Copy files to a new location

PoshTip #17 – Copy files to a new location

To copy a file from one folder to another, you can use the Copy-Item cmdlet :

Copy-Item -Path C:\folder1\file1.txt -Destination c:\folder2\file1.txt

You can copy and rename the file with the same cmdlet :

Copy-Item -Path C:\folder1\file1.txt -Destination c:\folder2\file1-renamed.txt

You can test if the destination folder exist with Test-Path cmdlet :

C:\> Test-Path C:\folder1\
True
C:\> Test-Path C:\folder2\
True
C:\> Test-Path C:\folder3\
False
About Nicolas 282 Articles
I work as an IT Production Manager, based in Paris (France) with a primary focus on Microsoft technologies. I have 10 years experience in administering Windows Servers. . I am a Microsoft MVP for Cloud & Datacenter Management. I also received the PowerShell Hero 2016 award by PowerShell.0rg. And finally, I am "MCSE: Cloud Platform and Infrastructure", "MCSA: Windows Servers", "Administering & Deploying SCCM", and CheckPoint CCSA certified.