1
1
---
2
- ms.date : 10/18/2018
2
+ ms.date : 5/30/2019
3
3
schema : 2.0.0
4
4
locale : en-us
5
5
keywords : powershell,cmdlet
@@ -36,9 +36,9 @@ Copy-Item -LiteralPath <String[]> [[-Destination] <String>] [-Container] [-Force
36
36
The ` Copy-Item ` cmdlet copies an item from one location to another location in the same namespace.
37
37
For instance, it can copy a file to a folder, but it cannot copy a file to a certificate drive.
38
38
39
- This cmdlet does not cut or delete the items being copied.
40
- The particular items that the cmdlet can copy depend on the PowerShell provider that exposes the item.
41
- For instance, it can copy files and directories in a file system drive and registry keys and entries in the registry drive.
39
+ This cmdlet does not cut or delete the items being copied. The particular items that the cmdlet can
40
+ copy depend on the PowerShell provider that exposes the item. For instance, it can copy files and
41
+ directories in a file system drive and registry keys and entries in the registry drive.
42
42
43
43
This cmdlet can copy and rename items in the same command.
44
44
To rename an item, enter the new name in the value of the ** Destination** parameter.
@@ -48,7 +48,7 @@ To rename an item and not copy it, use the `Rename-Item` cmdlet.
48
48
49
49
### Example 1: Copy a file to the specified directory
50
50
51
- This command copies the " mar1604.log.txt" file to the " C:\Presentation" directory.
51
+ This command copies the ` mar1604.log.txt ` file to the ` C:\Presentation ` directory.
52
52
The command does not delete the original file.
53
53
54
54
``` powershell
@@ -58,17 +58,19 @@ Copy-Item "C:\Wabash\Logfiles\mar1604.log.txt" -Destination "C:\Presentation"
58
58
### Example 2: Copy the contents of a directory to another directory
59
59
60
60
This command copies the entire contents of the "Logfiles" directory into the "Drawings" directory.
61
- If the "LogFiles" directory contains files in subdirectories, those subdirectories are copied with their file trees intact.
62
- The ** Container** parameter is set to "true" by default.
63
- This preserves the directory structure.
64
61
65
62
``` powershell
66
63
Copy-Item "C:\Logfiles\*" -Destination "C:\Drawings" -Recurse
67
64
```
68
65
66
+ If the "LogFiles" directory contains files in subdirectories, those subdirectories are copied with
67
+ their file trees intact. The ** Container** parameter is set to "true" by default.
68
+
69
+ This preserves the directory structure.
70
+
69
71
### Example 3: Copy the contents of a directory to another directory and create the destination directory if it does not exist
70
72
71
- This command copies the contents of the " C:\Logfiles" directory to the " C:\Drawings\Logs" directory.
73
+ This command copies the contents of the ` C:\Logfiles ` directory to the ` C:\Drawings\Logs ` directory.
72
74
It creates the "\Logs" subdirectory if it does not already exist.
73
75
74
76
``` powershell
@@ -77,25 +79,39 @@ Copy-Item C:\Logfiles -Destination C:\Drawings\Logs -Recurse
77
79
78
80
### Example 4: Copy a file to the specified directory and rename the file
79
81
80
- This command uses the ` Copy-Item ` cmdlet to copy the "Get-Widget.ps1" script from the "\\\\ Server01\Share" directory to the "\\\\ Server12\ScriptArchive" directory.
81
- As part of the copy operation, the command also changes the item name from "Get-Widget.ps1" to "Get-Widget.ps1.txt", so it can be attached to email messages.
82
+ This command uses the ` Copy-Item ` cmdlet to copy the ` Get-Widget.ps1 ` script from the
83
+ ` \\Server01\Share ` directory to the ` \\Server12\ScriptArchive ` directory.
84
+ As part of the copy operation, the command also changes the item name from ` Get-Widget.ps1 ` to
85
+ ` Get-Widget.ps1.txt ` , so it can be attached to email messages.
82
86
83
87
``` powershell
84
88
Copy-Item "\\Server01\Share\Get-Widget.ps1" -Destination "\\Server12\ScriptArchive\Get-Widget.ps1.txt"
85
89
```
86
90
87
91
## PARAMETERS
88
92
89
- ### -Credential
93
+ ### -Container
90
94
91
- Specifies a user account that has permission to perform this action.
92
- The default is the current user.
95
+ Indicates that this cmdlet preserves container objects during the copy operation.
93
96
94
- Type a user name, such as "User01" or "Domain01\User01", or enter a ** PSCredential** object, such as one generated by the ` Get-Credential ` cmdlet.
95
- If you type a user name, you are prompted for a password.
97
+ ``` yaml
98
+ Type : SwitchParameter
99
+ Parameter Sets : (All)
100
+ Aliases :
101
+
102
+ Required : False
103
+ Position : Named
104
+ Default value : True
105
+ Accept pipeline input : False
106
+ Accept wildcard characters : False
107
+ ` ` `
108
+
109
+ ### -Credential
96
110
97
- > [ !WARNING]
98
- > This parameter is not supported by any providers installed with Windows PowerShell.
111
+ > [!NOTE]
112
+ > This parameter is not supported by any providers installed with PowerShell.
113
+ > To impersonate another user, or elevate your credentials when running this cmdlet,
114
+ > use [Invoke-Command](../Microsoft.PowerShell.Core/Invoke-Command.md).
99
115
100
116
` ` ` yaml
101
117
Type : PSCredential
@@ -112,7 +128,9 @@ Accept wildcard characters: False
112
128
### -Destination
113
129
114
130
Specifies the path to the new location.
115
- To rename a copied item, include the new name in the value.
131
+ The default is the current directory.
132
+
133
+ To rename the item being copied, specify a new name in the value of the **Destination** parameter.
116
134
117
135
` ` ` yaml
118
136
Type : String
@@ -128,10 +146,11 @@ Accept wildcard characters: False
128
146
129
147
### -Exclude
130
148
131
- Specifies, as a string array, an item or items that this cmdlet excludes from the operation.
132
- The value of this parameter qualifies the **Path** parameter.
133
- Enter a path element or pattern, such as "*.txt".
134
- Wildcard characters are permitted.
149
+ Specifies, as a string array, an item or items that this cmdlet excludes in the operation. The value
150
+ of this parameter qualifies the **Path** parameter. Enter a path element or pattern, such as
151
+ ` *.txt`. Wildcard characters are permitted. The **Exclude** parameter is effective only when the
152
+ command includes the contents of an item, such as `C:\Windows\*`, where the wildcard character
153
+ specifies the contents of the `C:\Windows` directory.
135
154
136
155
` ` ` yaml
137
156
Type: String[]
@@ -147,11 +166,11 @@ Accept wildcard characters: True
147
166
148
167
# ## -Filter
149
168
150
- Specifies a filter in the format or language of the provider.
151
- The value of this parameter qualifies the **Path** parameter.
152
-
153
- The syntax of the filter, including the use of wildcard characters, depends on the provider.
154
- Filters are more efficient than other parameters, because the provider applies them when the cmdlet gets the objects rather than having PowerShell filter the objects after they are retrieved.
169
+ Specifies a filter to qualify the **Path** parameter. The [FileSystem](../Microsoft.PowerShell.Core/About/about_FileSystem_Provider.md)
170
+ provider is the only installed PowerShell provider that supports the use of filters. You can find
171
+ the syntax for the **FileSystem** filter language in [about_Wildcards](../Microsoft.PowerShell.Core/About/about_Wildcards.md).
172
+ Filters are more efficient than other parameters, because the provider applies them when the cmdlet
173
+ gets the objects rather than having PowerShell filter the objects after they are retrieved.
155
174
156
175
` ` ` yaml
157
176
Type: String
@@ -167,7 +186,8 @@ Accept wildcard characters: True
167
186
168
187
# ## -Force
169
188
170
- Indicates that this cmdlet copies items that cannot otherwise be changed, such as copying over a read-only file or alias.
189
+ Indicates that this cmdlet copies items that cannot otherwise be changed, such as copying over a
190
+ read-only file or alias.
171
191
172
192
` ` ` yaml
173
193
Type: SwitchParameter
@@ -176,17 +196,18 @@ Aliases:
176
196
177
197
Required: False
178
198
Position: Named
179
- Default value : None
199
+ Default value: False
180
200
Accept pipeline input: False
181
201
Accept wildcard characters: False
182
202
` ` `
183
203
184
204
# ## -Include
185
205
186
- Specifies, as a string array, an item or items that this cmdlet includes in the operation.
187
- The value of this parameter qualifies the **Path** parameter.
188
- Enter a path element or pattern, such as "*.txt".
189
- Wildcard characters are permitted.
206
+ Specifies, as a string array, an item or items that this cmdlet includes in the operation. The value
207
+ of this parameter qualifies the **Path** parameter. Enter a path element or pattern, such as
208
+ ` "*.txt"` . Wildcard characters are permitted. The **Include** parameter is effective only when the
209
+ command includes the contents of an item, such as `C:\Windows\*`, where the wildcard character
210
+ specifies the contents of the `C:\Windows` directory.
190
211
191
212
` ` ` yaml
192
213
Type: String[]
@@ -197,16 +218,17 @@ Required: False
197
218
Position: Named
198
219
Default value: None
199
220
Accept pipeline input: False
200
- Accept wildcard characters : False
221
+ Accept wildcard characters: True
201
222
` ` `
202
223
203
224
# ## -LiteralPath
204
225
205
- Specifies a path to the item.
206
- Unlike the **Path** parameter, the value of **LiteralPath** is used exactly as it is typed.
207
- No characters are interpreted as wildcards.
208
- If the path includes escape characters, enclose it in single quotation marks.
209
- Single quotation marks tell PowerShell not to interpret any characters as escape sequences.
226
+ Specifies a path to one or more locations. The value of **LiteralPath** is used exactly as it is
227
+ typed. No characters are interpreted as wildcards. If the path includes escape characters, enclose
228
+ it in single quotation marks. Single quotation marks tell PowerShell not to interpret any characters
229
+ as escape sequences.
230
+
231
+ For more information, see [about_Quoting_Rules](../Microsoft.Powershell.Core/About/about_Quoting_Rules.md).
210
232
211
233
` ` ` yaml
212
234
Type: String[]
@@ -232,14 +254,15 @@ Aliases:
232
254
233
255
Required: False
234
256
Position: Named
235
- Default value : None
257
+ Default value: False
236
258
Accept pipeline input: False
237
259
Accept wildcard characters: False
238
260
` ` `
239
261
240
262
# ## -Path
241
263
242
264
Specifies, as a string array, the path to the items to copy.
265
+ Wildcard characters are permitted.
243
266
244
267
` ` ` yaml
245
268
Type: String[]
@@ -250,7 +273,7 @@ Required: True
250
273
Position: 1
251
274
Default value: None
252
275
Accept pipeline input: True (ByPropertyName, ByValue)
253
- Accept wildcard characters : False
276
+ Accept wildcard characters: True
254
277
` ` `
255
278
256
279
# ## -Recurse
@@ -264,7 +287,7 @@ Aliases:
264
287
265
288
Required: False
266
289
Position: Named
267
- Default value : None
290
+ Default value: False
268
291
Accept pipeline input: False
269
292
Accept wildcard characters: False
270
293
` ` `
0 commit comments