Skip to content

Fixes #2293 update yaml blocks #4369

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
109 changes: 66 additions & 43 deletions reference/3.0/Microsoft.PowerShell.Management/Copy-Item.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
ms.date: 10/18/2018
ms.date: 5/30/2019
schema: 2.0.0
locale: en-us
keywords: powershell,cmdlet
Expand Down Expand Up @@ -36,9 +36,9 @@ Copy-Item -LiteralPath <String[]> [[-Destination] <String>] [-Container] [-Force
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 cannot copy a file to a certificate drive.

This cmdlet does not cut or delete the items being copied.
The particular items that the cmdlet can copy depend on the PowerShell provider that exposes the item.
For instance, it can copy files and directories in a file system drive and registry keys and entries in the registry drive.
This cmdlet does not cut or delete the items being copied. The particular items that the cmdlet can
copy depend on the PowerShell provider that exposes the item. For instance, it can copy files and
directories in a file system drive and registry keys and entries in the registry drive.

This cmdlet can copy and rename items in the same command.
To rename an item, enter the new name in the value of the **Destination** parameter.
Expand All @@ -48,7 +48,7 @@ To rename an item and not copy it, use the `Rename-Item` cmdlet.

### Example 1: Copy a file to the specified directory

This command copies the "mar1604.log.txt" file to the "C:\Presentation" directory.
This command copies the `mar1604.log.txt` file to the `C:\Presentation` directory.
The command does not delete the original file.

```powershell
Expand All @@ -58,17 +58,19 @@ Copy-Item "C:\Wabash\Logfiles\mar1604.log.txt" -Destination "C:\Presentation"
### Example 2: Copy the contents of a directory to another directory

This command copies the entire contents of the "Logfiles" directory into the "Drawings" directory.
If the "LogFiles" directory contains files in subdirectories, those subdirectories are copied with their file trees intact.
The **Container** parameter is set to "true" by default.
This preserves the directory structure.

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

If the "LogFiles" directory contains files in subdirectories, those subdirectories are copied with
their file trees intact. The **Container** parameter is set to "true" by default.

This preserves the directory structure.

### Example 3: Copy the contents of a directory to another directory and create the destination directory if it does not exist

This command copies the contents of the "C:\Logfiles" directory to the "C:\Drawings\Logs" directory.
This command copies the contents of the `C:\Logfiles` directory to the `C:\Drawings\Logs` directory.
It creates the "\Logs" subdirectory if it does not already exist.

```powershell
Expand All @@ -77,25 +79,39 @@ Copy-Item C:\Logfiles -Destination C:\Drawings\Logs -Recurse

### Example 4: Copy a file to the specified directory and rename the file

This command uses the `Copy-Item` cmdlet to copy the "Get-Widget.ps1" script from the "\\\\Server01\Share" directory to the "\\\\Server12\ScriptArchive" directory.
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.
This command uses the `Copy-Item` cmdlet to copy the `Get-Widget.ps1` script from the
`\\Server01\Share` directory to the `\\Server12\ScriptArchive` directory.
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.

```powershell
Copy-Item "\\Server01\Share\Get-Widget.ps1" -Destination "\\Server12\ScriptArchive\Get-Widget.ps1.txt"
```

## PARAMETERS

### -Credential
### -Container

Specifies a user account that has permission to perform this action.
The default is the current user.
Indicates that this cmdlet preserves container objects during the copy operation.

Type a user name, such as "User01" or "Domain01\User01", or enter a **PSCredential** object, such as one generated by the `Get-Credential` cmdlet.
If you type a user name, you are prompted for a password.
```yaml
Type: SwitchParameter
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: True
Accept pipeline input: False
Accept wildcard characters: False
```

### -Credential

> [!WARNING]
> This parameter is not supported by any providers installed with Windows PowerShell.
> [!NOTE]
> This parameter is not supported by any providers installed with PowerShell.
> To impersonate another user, or elevate your credentials when running this cmdlet,
> use [Invoke-Command](../Microsoft.PowerShell.Core/Invoke-Command.md).

```yaml
Type: PSCredential
Expand All @@ -112,7 +128,9 @@ Accept wildcard characters: False
### -Destination

Specifies the path to the new location.
To rename a copied item, include the new name in the value.
The default is the current directory.

To rename the item being copied, specify a new name in the value of the **Destination** parameter.

```yaml
Type: String
Expand All @@ -128,10 +146,11 @@ Accept wildcard characters: False

### -Exclude

Specifies, as a string array, an item or items that this cmdlet excludes from the operation.
The value of this parameter qualifies the **Path** parameter.
Enter a path element or pattern, such as "*.txt".
Wildcard characters are permitted.
Specifies, as a string array, an item or items that this cmdlet excludes in the operation. The value
of this parameter qualifies the **Path** parameter. Enter a path element or pattern, such as
`*.txt`. Wildcard characters are permitted. The **Exclude** parameter is effective only when the
command includes the contents of an item, such as `C:\Windows\*`, where the wildcard character
specifies the contents of the `C:\Windows` directory.

```yaml
Type: String[]
Expand All @@ -147,11 +166,11 @@ Accept wildcard characters: True

### -Filter

Specifies a filter in the format or language of the provider.
The value of this parameter qualifies the **Path** parameter.

The syntax of the filter, including the use of wildcard characters, depends on the provider.
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.
Specifies a filter to qualify the **Path** parameter. The [FileSystem](../Microsoft.PowerShell.Core/About/about_FileSystem_Provider.md)
provider is the only installed PowerShell provider that supports the use of filters. You can find
the syntax for the **FileSystem** filter language in [about_Wildcards](../Microsoft.PowerShell.Core/About/about_Wildcards.md).
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.

```yaml
Type: String
Expand All @@ -167,7 +186,8 @@ Accept wildcard characters: True

### -Force

Indicates that this cmdlet copies items that cannot otherwise be changed, such as copying over a read-only file or alias.
Indicates that this cmdlet copies items that cannot otherwise be changed, such as copying over a
read-only file or alias.

```yaml
Type: SwitchParameter
Expand All @@ -176,17 +196,18 @@ Aliases:

Required: False
Position: Named
Default value: None
Default value: False
Accept pipeline input: False
Accept wildcard characters: False
```

### -Include

Specifies, as a string array, an item or items that this cmdlet includes in the operation.
The value of this parameter qualifies the **Path** parameter.
Enter a path element or pattern, such as "*.txt".
Wildcard characters are permitted.
Specifies, as a string array, an item or items that this cmdlet includes in the operation. The value
of this parameter qualifies the **Path** parameter. Enter a path element or pattern, such as
`"*.txt"`. Wildcard characters are permitted. The **Include** parameter is effective only when the
command includes the contents of an item, such as `C:\Windows\*`, where the wildcard character
specifies the contents of the `C:\Windows` directory.

```yaml
Type: String[]
Expand All @@ -197,16 +218,17 @@ Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
Accept wildcard characters: True
```

### -LiteralPath

Specifies a path to the item.
Unlike the **Path** parameter, the value of **LiteralPath** is used exactly as it is typed.
No characters are interpreted as wildcards.
If the path includes escape characters, enclose it in single quotation marks.
Single quotation marks tell PowerShell not to interpret any characters as escape sequences.
Specifies a path to one or more locations. The value of **LiteralPath** is used exactly as it is
typed. No characters are interpreted as wildcards. If the path includes escape characters, enclose
it in single quotation marks. Single quotation marks tell PowerShell not to interpret any characters
as escape sequences.

For more information, see [about_Quoting_Rules](../Microsoft.Powershell.Core/About/about_Quoting_Rules.md).

```yaml
Type: String[]
Expand All @@ -232,14 +254,15 @@ Aliases:

Required: False
Position: Named
Default value: None
Default value: False
Accept pipeline input: False
Accept wildcard characters: False
```

### -Path

Specifies, as a string array, the path to the items to copy.
Wildcard characters are permitted.

```yaml
Type: String[]
Expand All @@ -250,7 +273,7 @@ Required: True
Position: 1
Default value: None
Accept pipeline input: True (ByPropertyName, ByValue)
Accept wildcard characters: False
Accept wildcard characters: True
```

### -Recurse
Expand All @@ -264,7 +287,7 @@ Aliases:

Required: False
Position: Named
Default value: None
Default value: False
Accept pipeline input: False
Accept wildcard characters: False
```
Expand Down
Loading