The following articles provide a brief introduction to carrying out file system management tasks by using Windows PowerShell; these tasks include such things as creating, renaming, copying, and deleting files and folders. As is so often the case with Windows PowerShell, the code snippets found in these articles can either be included within a Windows PowerShell script or typed directly into the Windows PowerShell console.
Copy Files or Folders
Create a New File or Folder
Delete a File or Folder (Or Other Objects)
Move a File or Folder
Rename a File or Folder
Replicate (and Improve Upon) the DIR Command
Retrieve a Specific Item
Verify the Existence of a File or Folder
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