PowerShell by Patrik

Copy-Item Cmdlet

The Copy-Item cmdlet copies an item from one location to another location in the same namespace. For instance, it can copy a file to a folder, but it can't copy a file to a certificate drive.

Copy a file to the specified directory

This example copies the mar1604.log.txt file to the C:\Presentation directory. The original file isn't deleted.

Copy-Item "C:\Wabash\Logfiles\mar1604.log.txt" -Destination "C:\Presentation"

Copy directory contents to an existing directory

This example copies the contents of the C:\Logfiles directory into the existing C:\Drawings directory. The Logfiles directory isn't copied.

If the Logfiles directory contains files in subdirectories, those subdirectories are copied with their file trees intact. By default, the Container parameter is set to True, which preserves the directory structure.

Copy-Item -Path "C:\Logfiles\*" -Destination "C:\Drawings" -Recurse

Further information and samples can be found at Copy-Item (Microsoft.PowerShell.Management) - PowerShell | Microsoft Docs

Comments