The Copy-Item
cmdlet in PowerShell is used to copy files and directories from one location to another.
Here’s how to use Copy-Item
:
- Open PowerShell by searching for it in the Start menu or by pressing Win + X and selecting “Windows PowerShell” or “Windows PowerShell (Admin)”.
- Once PowerShell is open, you can use the
Copy-Item
cmdlet followed by the path of the item you want to copy and the destination path where you want to copy it. For example:
- To copy a file:
Copy-Item -Path C:\Path\ToFile.txt -Destination D:\Destination
- To copy a directory and all its contents recursively:
Copy-Item -Path C:\Path\To\Directory -Destination D:\Destination -Recurse
- You can also use parameters such as
-Force
to overwrite existing items without prompting and-Verbose
to display detailed information about the operation.
- After executing the
Copy-Item
cmdlet with the desired parameters, PowerShell will copy the specified item(s) to the destination location.
Source for More Information
Here’s a source where you can find more detailed information about Copy-Item
and other PowerShell cmdlets:
- Microsoft Docs: Copy-Item cmdlet
The Microsoft Docs page provides comprehensive documentation on PowerShell cmdlets, including Copy-Item
, with detailed explanations, examples, and usage scenarios.