Questions tagged [copy-item]

Copy-Item is a powershell cmdlet that copies an item from one location to another.

Copy-Item is a powershell cmdlet that copies an item from one location to another in the same namespace. For example, it can copy a file to a folder, but it cannot copy a file to a certificate drive.

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

Copy-Item can copy and rename items in the same command. To rename an item, enter the new name in the value of the Destination parameter. To rename an item without copying it, use the Rename-Item cmdlet.

Output

  • None or an object representing the copied item.
    When you use the PassThru parameter, Copy-Item returns an object that represents the copied item. Otherwise, this cmdlet does not generate any output.
282 questions
90
votes
12 answers

Progress during large file copy (Copy-Item & Write-Progress?)

Is there any way to copy a really large file (from one server to another) in PowerShell AND display its progress? There are solutions out there to use Write-Progress in conjunction with looping to copy many files and display progress. However I…
Jason Jarrett
  • 3,857
  • 1
  • 27
  • 28
47
votes
2 answers

What is the meaning of Powershell's Copy-Item's -container argument?

I am writing a script for MS PowerShell. This script uses the Copy-Item command. One of the optional arguments to this command is "-container". The documentation for the argument states that specifying this argument "Preserves container objects…
Mark Meuer
  • 7,200
  • 6
  • 43
  • 64
33
votes
4 answers

Get the list of files that are getting copied in PowerShell

I am using the PowerShell Copy-Item command to copy a directory with files to another location. I want to display all the files on the console that are getting copied so that I know the status of the copy command.
tusharmath
  • 10,622
  • 12
  • 56
  • 83
31
votes
3 answers

PowerShell - suppress Copy-Item 'Folder already exists' error

When I run a recursive Copy-Item from a folder that has sub folders to a new folder that contains the same sub folders as the original, it throws an error when the subfolders already exist. How can I suppress this because it is a false negative and…
user1161625
  • 642
  • 1
  • 8
  • 13
30
votes
4 answers

Powershell Copy-Item but only copy changed files

I am trying to recurse through a directory and copy it from A to B. That can be done with the following: Copy-Item C:\MyTest C:\MyTest2 –recurse I want to be able though to only copy new files (ones that exist in src but not dest) and also only…
James Turns
21
votes
3 answers

Need help on Powershell Copy-Item from network drives

I am trying to use Copy-Item from remote machine to another remote machine with the command: Copy-Item -Path "\\machine1\abc\123\log 1.zip" -Destination "\\machine2\\c$\Logs\" I am constantly getting Error "Cannot find Path "\\machine1\abc\123\log…
Geeth
  • 321
  • 1
  • 2
  • 4
18
votes
1 answer

Powershell 3.0: COPY-ITEM Filter or Include options not working

Does the -Filter or -Include parameter work for anyone when using Powershell 3.0? I've tried both of the following commands: Copy-Item -Path c:\temp -Include "*.TXT" -Destination C:\temp2 and Copy-Item -Path c:\temp -Filter "*.TXT" -Destination…
inquisitive_one
  • 1,465
  • 7
  • 32
  • 56
15
votes
1 answer

PowerShell use xcopy, robocopy or copy-item

The reason for switching from batch files to powershell scripts is to improve error checking of the process. Does the cmdlet for copying have advantages in this regard? If a batch file already exists that uses xcopy to copy files by filename…
Adam
  • 1,825
  • 1
  • 17
  • 24
15
votes
5 answers

Get-ChildItem and Copy-Item explanation

Why does gci $from -Recurse | copy-item -Destination $to -Recurse -Force -Container not behave in the same way as copy-item $from $to -Recurse -Force ? I think it should be the same, but somehow it's not. Why?
Dejan Dakić
  • 2,418
  • 2
  • 25
  • 39
7
votes
3 answers

Want to wait till copy complete using Powershell Copy-Item

I am copying files from One Windows machine to another using Copy-Item in Powershell script. But I want to wait till copy completes, Powershell Copy-Item is non-blocking call means, it just triggers copy and returns to script however I want to wait…
VarunVyas
  • 1,357
  • 6
  • 15
  • 23
6
votes
1 answer

Copy-Item when destination folder exists or doesn't

When destination folder exists the right way of copying files is defined here Copy-Item 'C:\Source\*' 'C:\Destination' -Recurse -Force If destination folder doesn't exist, some files in the source subfolders are copied straight into destination,…
Kimi
  • 13,621
  • 9
  • 55
  • 84
6
votes
1 answer

Copy-Item inconsistent behavior?

Consider this directory structure: C:\temp\A\file.txt C:\temp\B If I run the command Copy-Item "C:\temp\A" "C:\temp\B\A" -Recurse -Force -ErrorAction Stop I have C:\temp\A\file.txt C:\temp\B\A\file.txt If, starting from this new situation, I run…
Tomd
  • 193
  • 1
  • 10
6
votes
2 answers

PowerShell copy fails without warning

Howdy, am trying to copy a file from IE cache to somewhere else. This works on w7, but not Vista Ultimate. In short: copy-item $f -Destination "$targetDir" -force (I also tried $f.fullname) The full script: $targetDir =…
boink
  • 61
  • 1
  • 2
6
votes
1 answer

PowerShell: Copy-Item Cannot find path

I'm trying to get PowerShell to copy files from a remote computer (on which I have admin rights through AD) to the local computer. It fails in the strangest place. Here's a snippet of the script: $configs = Get-ChildItem -Recurse -ErrorAction…
AndreasKnudsen
  • 3,453
  • 5
  • 28
  • 33
6
votes
4 answers

How Do I copy the files and the Folder Tree to Remote Machine?

I have two machines Server A and Server B, and I want to copy all the files and folder tree from Server A to Server B using PowerShell. I have tried the command given below, but it copies only the files in the folder and does not create the folder…
Selwyn
  • 1,621
  • 6
  • 21
  • 38
1
2 3
18 19