Copying Files or Folders from PowerShell
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 Windows 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. To rename an item and not copy it, use the Rename-Item cmdlet.

Following command copies the file Test.txt from the C:\Scripts folder to the C:\Test folder:



Code:

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





Following command copies all the items in C:\Scripts (including subfolders) to C:\Test folder:



Code:

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





Following command copies only the .txt files in C:\Scripts to C:\Test:



Code:

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:


Code:



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