Skip to content

Commit ca6df6b

Browse files
authored
Document behavior of wildcard matching when -Destination doesn't exist (#12670)
1 parent a7a1533 commit ca6df6b

File tree

4 files changed

+79
-15
lines changed

4 files changed

+79
-15
lines changed

reference/5.1/Microsoft.PowerShell.Management/Copy-Item.md

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,10 @@ Copy-Item -Path "C:\Logfiles" -Destination "C:\Drawings\Logs" -Recurse
114114
> trees, are copied to the new destination directory. For example:
115115
>
116116
> `Copy-Item -Path "C:\Logfiles\*" -Destination "C:\Drawings\Logs" -Recurse`
117+
>
118+
> If the `C:\Logfiles` only contains files and no subdirectories and `C:\Drawings\Logs` doesn't
119+
> exist, all files in `C:\Logfiles` are copied to `C:\Drawings\Logs` as a file. The `C:\Drawings`
120+
> file is a copy of the last file in the `C:\Logfiles` directory.
117121
118122
### Example 4: Copy a file to the specified directory and rename the file
119123

@@ -123,7 +127,11 @@ operation, the command changes the item name from `Get-Widget.ps1` to `Get-Widge
123127
can be safely attached to email messages.
124128

125129
```powershell
126-
Copy-Item "\\Server01\Share\Get-Widget.ps1" -Destination "\\Server12\ScriptArchive\Get-Widget.ps1.txt"
130+
$copyParams = @{
131+
Path = "\\Server01\Share\Get-Widget.ps1"
132+
Destination = "\\Server12\ScriptArchive\Get-Widget.ps1.txt"
133+
}
134+
Copy-Item @copyParams
127135
```
128136

129137
### Example 5: Copy a file to a remote computer
@@ -181,7 +189,12 @@ The `Copy-Item` cmdlet copies `scriptingexample.ps1` from the `D:\Folder004` fol
181189

182190
```powershell
183191
$Session = New-PSSession -ComputerName "Server04" -Credential "Contoso\User01"
184-
Copy-Item "D:\Folder004\scriptingexample.ps1" -Destination "C:\Folder004_Copy\scriptingexample_copy.ps1" -ToSession $Session
192+
$copyParams = @{
193+
Path = "D:\Folder004\scriptingexample.ps1"
194+
Destination = "C:\Folder004_Copy\scriptingexample_copy.ps1"
195+
ToSession = $Session
196+
}
197+
Copy-Item @copyParams
185198
```
186199

187200
### Example 9: Copy a remote file to the local computer
@@ -226,7 +239,13 @@ copied with their file trees intact.
226239

227240
```powershell
228241
$Session = New-PSSession -ComputerName "Server01" -Credential "Contoso\User01"
229-
Copy-Item "C:\MyRemoteData\scripts" -Destination "D:\MyLocalData\scripts" -FromSession $Session -Recurse
242+
$copyParams = @{
243+
Path = "C:\MyRemoteData\scripts"
244+
Destination = "D:\MyLocalData\scripts"
245+
FromSession = $Session
246+
Recurse = $true
247+
}
248+
Copy-Item @copyParams
230249
```
231250

232251
### Example 12: Recursively copy files from a folder tree into the current folder
@@ -541,7 +560,8 @@ typed. No characters are interpreted as wildcards. If the path includes escape c
541560
it in single quotation marks. Single quotation marks tell PowerShell not to interpret any characters
542561
as escape sequences.
543562
544-
For more information, see [about_Quoting_Rules](../Microsoft.Powershell.Core/About/about_Quoting_Rules.md).
563+
For more information, see
564+
[about_Quoting_Rules](../Microsoft.Powershell.Core/About/about_Quoting_Rules.md).
545565
546566
```yaml
547567
Type: System.String[]

reference/7.4/Microsoft.PowerShell.Management/Copy-Item.md

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
external help file: Microsoft.PowerShell.Commands.Management.dll-Help.xml
33
Locale: en-US
44
Module Name: Microsoft.PowerShell.Management
5-
ms.date: 11/04/2024
5+
ms.date: 01/17/2026
66
online version: https://learn.microsoft.com/powershell/module/microsoft.powershell.management/copy-item?view=powershell-7.4&WT.mc_id=ps-gethelp
77
schema: 2.0.0
88
aliases:
@@ -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
122126
can 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
540559
it in single quotation marks. Single quotation marks tell PowerShell not to interpret any characters
541560
as 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
546566
Type: System.String[]

reference/7.5/Microsoft.PowerShell.Management/Copy-Item.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
external help file: Microsoft.PowerShell.Commands.Management.dll-Help.xml
33
Locale: en-US
44
Module Name: Microsoft.PowerShell.Management
5-
ms.date: 11/04/2024
5+
ms.date: 01/17/2026
66
online version: https://learn.microsoft.com/powershell/module/microsoft.powershell.management/copy-item?view=powershell-7.5&WT.mc_id=ps-gethelp
77
schema: 2.0.0
88
aliases:
@@ -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

reference/7.6/Microsoft.PowerShell.Management/Copy-Item.md

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
external help file: Microsoft.PowerShell.Commands.Management.dll-Help.xml
33
Locale: en-US
44
Module Name: Microsoft.PowerShell.Management
5-
ms.date: 11/04/2024
5+
ms.date: 01/17/2026
66
online version: https://learn.microsoft.com/powershell/module/microsoft.powershell.management/copy-item?view=powershell-7.6&WT.mc_id=ps-gethelp
77
schema: 2.0.0
88
aliases:
@@ -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
122126
can 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
540559
it in single quotation marks. Single quotation marks tell PowerShell not to interpret any characters
541560
as 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
546566
Type: System.String[]

0 commit comments

Comments
 (0)