PowerShell Copy-Item Cmdlet

PowerShell Copy-Item Cmdlet

PowerShell Copy-Item Cmdlet

Hello Everyone

Welcome to CloudAffaire and this is Debjeet.

In the last blog post, we have discussed Remove-Item cmdlet in PowerShell.

https://cloudaffaire.com/powershell-remove-item-cmdlet/

In this blog post, we will discuss Copy-Item cmdlet in PowerShell. You can use Copy-Item cmdlet to copy files and directories in PowerShell. Copy-Item cmdlet creates a copy of the source item and places it to the destination location. You can also rename the target item while copying by simply mentioning the new name in the destination. If you want to rename the source file without a copy, please use Rename-Item cmdlet. You can also copy registry keys using Copy-Item cmdlet. If you want to copy the item in a remote system, you can use Copy-Item cmdlet in conjunction with any remote management cmdlet like New-PSSession.

Copy-Item Cmdlet Syntax:

Copy-Item Cmdlet Argument List:

  • Confirm: Prompts you for confirmation before running the cmdlet.
  • Container: Indicates that this cmdlet preserves container objects during the copy operation. By default, the Container parameter is set to True.
  • Credential: To impersonate another user or elevate your credentials.
  • Destination: Specifies the path to the new location. The default is the current directory. To rename the item being copied, specify a new name in the value of the Destination parameter.
  • Exclude: 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.
  • Filter: Specifies a filter to qualify the Path parameter. The FileSystem provider is the only installed PowerShell provider that supports the use of filters.
  • Force: Forces the cmdlet to remove items that cannot otherwise be changed, such as hidden or read-only files or read-only aliases or variables.
  • FromSession: Specifies the PSSession object from which a remote file is being copied. When you use this parameter, the Path and LiteralPath parameters refer to the local path on the remote machine.
  • 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.
  • LiteralPath: 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.
  • PassThru: Returns an object that represents the item with which you’re working. By default, this cmdlet doesn’t generate any output.
  • Path: Specifies a path of the items being removed. Wildcard characters are permitted.
  • Recurse: Indicates that this cmdlet deletes the items in the specified locations and in all child items of the locations.
  • ToSession: Specifies the PSSession object to which a remote file is being copied. When you use this parameter, the Destination parameter refers to the local path on the remote machine.
  • WhatIf: Shows what would happen if the cmdlet runs. The cmdlet is not run.

PowerShell Copy-Item Cmdlet:

Copy A File In PowerShell:

Copy A File In PowerShell, Renaming It In Destination:

Copy Multiple Files At Once In PowerShell:

Copy A Directory Along With Its Contents In PowerShell:

Copy Only Contents Of A Directory In PowerShell:

Copy A Directory Along With Its Contents In PowerShell, Renaming The Directory In Target:

Copy Multiple Directories At Once In PowerShell:

Copy A File To A Remote Computer In PowerShell:

Copy A Directory To A Remote Computer In PowerShell:

Copy A File From A Remote Computer In PowerShell:

Copy A Directory From A Remote Computer In PowerShell:

Hope you have enjoyed this article. In the next blog post, we will discuss Move-Item cmdlet in PowerShell.

To get more details on PowerShell, kindly follow below official documentation

https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about?view=powershell-5.1

 

Leave a Reply

Close Menu