Export (0) Print
Expand All
Expand Minimize

Using the Copy-Item Cmdlet

Copying Files or Folders

Want to a copy a file or folder to a new location? Then you want the Copy-Item cmdlet. For example, here’s a command that copies the file Test.txt from the C:\Scripts folder to the C:\Test folder:

Copy-Item c:\scripts\test.txt c:\test

Want to copy all the items in C:\Scripts (including subfolders) to C:\Test? Then simply use a wildcard character, like so:

Copy-Item c:\scripts\* c:\test

You’re way ahead of us: yes, this next command copies only the .txt files in C:\Scripts to C:\Test:

Copy-Item c:\scripts\*.txt c:\test

Finally, this command puts a copy of the folder C:\Scripts inside the folder C:\Test; in other words, the copied information will be copied to a folder named C:\Test\Scripts. Here’s the command:

Copy-Item c:\scripts c:\test -recurse

Incidentally, the -recurse parameter is absolutely crucial here; leave it out and a Scripts folder will be created in C:\Test, but none of the files and folders in C:\Scripts will be copied to the new location; you’ll create a C:\Test\Scripts folder, but there won’t be anything in it.

Copy-Item Aliases
  • cpi

  • cp

  • copy

Related Links

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
© 2014 Microsoft