22external help file : Microsoft.PowerShell.Commands.Management.dll-Help.xml
33Locale : en-US
44Module Name : Microsoft.PowerShell.Management
5- ms.date : 11/04/2024
5+ ms.date : 01/17/2026
66online version : https://learn.microsoft.com/powershell/module/microsoft.powershell.management/copy-item?view=powershell-7.4&WT.mc_id=ps-gethelp
77schema : 2.0.0
88aliases :
@@ -113,6 +113,10 @@ Copy-Item -Path "C:\Logfiles" -Destination "C:\Drawings\Logs" -Recurse
113113> trees, are copied to the new destination directory. For example:
114114>
115115> ` Copy-Item -Path "C:\Logfiles\*" -Destination "C:\Drawings\Logs" -Recurse `
116+ >
117+ > If the ` C:\Logfiles ` only contains files and no subdirectories and ` C:\Drawings\Logs ` doesn't
118+ > exist, all files in ` C:\Logfiles ` are copied to ` C:\Drawings\Logs ` as a file. The ` C:\Drawings `
119+ > file is a copy of the last file in the ` C:\Logfiles ` directory.
116120
117121### Example 4: Copy a file to the specified directory and rename the file
118122
@@ -122,7 +126,11 @@ operation, the command changes the item name from `Get-Widget.ps1` to `Get-Widge
122126can be safely attached to email messages.
123127
124128``` powershell
125- Copy-Item "\\Server01\Share\Get-Widget.ps1" -Destination "\\Server12\ScriptArchive\Get-Widget.ps1.txt"
129+ $copyParams = @{
130+ Path = "\\Server01\Share\Get-Widget.ps1"
131+ Destination = "\\Server12\ScriptArchive\Get-Widget.ps1.txt"
132+ }
133+ Copy-Item @copyParams
126134```
127135
128136### Example 5: Copy a file to a remote computer
@@ -180,7 +188,12 @@ The `Copy-Item` cmdlet copies `scriptingexample.ps1` from the `D:\Folder004` fol
180188
181189``` powershell
182190$Session = New-PSSession -ComputerName "Server04" -Credential "Contoso\User01"
183- Copy-Item "D:\Folder004\scriptingexample.ps1" -Destination "C:\Folder004_Copy\scriptingexample_copy.ps1" -ToSession $Session
191+ $copyParams = @{
192+ Path = "D:\Folder004\scriptingexample.ps1"
193+ Destination = "C:\Folder004_Copy\scriptingexample_copy.ps1"
194+ ToSession = $Session
195+ }
196+ Copy-Item @copyParams
184197```
185198
186199### Example 9: Copy a remote file to the local computer
@@ -225,7 +238,13 @@ copied with their file trees intact.
225238
226239``` powershell
227240$Session = New-PSSession -ComputerName "Server01" -Credential "Contoso\User01"
228- Copy-Item "C:\MyRemoteData\scripts" -Destination "D:\MyLocalData\scripts" -FromSession $Session -Recurse
241+ $copyParams = @{
242+ Path = "C:\MyRemoteData\scripts"
243+ Destination = "D:\MyLocalData\scripts"
244+ FromSession = $Session
245+ Recurse = $true
246+ }
247+ Copy-Item @copyParams
229248```
230249
231250### Example 12: Recursively copy files from a folder tree into the current folder
@@ -540,7 +559,8 @@ typed. No characters are interpreted as wildcards. If the path includes escape c
540559it in single quotation marks. Single quotation marks tell PowerShell not to interpret any characters
541560as escape sequences.
542561
543- For more information, see [about_Quoting_Rules](../Microsoft.Powershell.Core/About/about_Quoting_Rules.md).
562+ For more information, see
563+ [about_Quoting_Rules](../Microsoft.Powershell.Core/About/about_Quoting_Rules.md).
544564
545565` ` ` yaml
546566Type : System.String[]
0 commit comments