

The subfolders are copied with their file trees intact. The Copy-Item cmdlet copies the entire contents from the D:\Folder003 folder to theĬ:\Folder003_Copy directory on the remote computer using the session information stored in the $Session = New-PSSession -ComputerName "Server02" -Credential "Contoso\User01"Ĭopy-Item "D:\Folder002\" -Destination "C:\Folder002_Copy\" -ToSession $Session Example 7: Recursively copy the entire contents of a folder to a remote computer The operation creates the Folder002_Copyįolder if it doesn't already exist.

Any subfolders orįiles aren't copied without using the Recurse switch. Remote computer using the session information stored in the $Session variable.

The Copy-Item cmdlet copies the D:\Folder002 folder to the C:\Folder002_Copy directory on the $Session = New-PSSession -ComputerName "Server01" -Credential "Contoso\User01"Ĭopy-Item "D:\Folder001\test.log" -Destination "C:\Folder001_Copy\" -ToSession $Session Example 6: Copy a folder to a remote computer The Copy-Item cmdlet copies test.log from the D:\Folder001 folder to the C:\Folder001_Copyįolder on the remote computer using the session information stored in the $Session variable. Copy-Item "\\Server01\Share\Get-Widget.ps1" -Destination "\\Server12\ScriptArchive\" Example 5: Copy a file to a remote computerĪ session is created to the remote computer named Server01 with the credential ofĬontoso\User01 and stores the results in the variable named $Session.

Operation, the command changes the item name from Get-Widget.ps1 to, so itĬan be safely attached to email messages. \\Server01\Share directory to the \\Server12\ScriptArchive directory. This example uses the Copy-Item cmdlet to copy the Get-Widget.ps1 script from the For example:Ĭopy-Item -Path "C:\Logfiles\*" -Destination "C:\Drawings\Logs" -Recurse Example 4: Copy a file to the specified directory and rename the file Trees, are copied to the new destination directory. If the Path includes \*, all the directory's file contents, including the subdirectory Copy-Item -Path "C:\Logfiles\*" -Destination "C:\Drawings" -Recurse By default, the Container parameter is set to True, which preserves theĭirectory structure. If the Logfiles directory has files in subdirectories, those subdirectories are copied with theirįile trees intact. This example copies the contents of the C:\Logfiles directory into the existing C:\Drawingsĭirectory. Copy-Item "C:\Wabash\Logfiles\" -Destination "C:\Presentation" Example 2: Copy directory contents to an existing directory This example copies the file to the C:\Presentation directory. Examples Example 1: Copy a file to the specified directory To rename an item and not copy it, use the Rename-ItemĬmdlet. This cmdlet can copy and rename items in the same command. For instance, it can copy files andĭirectories in a file system drive and registry keys and entries in the registry drive. The particular items that the cmdlet canĬopy depend on the PowerShell provider that exposes the item. This cmdlet doesn't cut or delete the items being copied. The Copy-Item cmdlet copies an item from one location to another location in the same namespace.įor instance, it can copy a file to a folder, but it can't copy a file to a certificate drive. Copies an item from one location to another.
