- Trending Categories
- Data Structure
- Operating System
- C Programming
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to copy files/folders to the remote location in the PowerShell?
To copy files or folders to or from the remote location, you need to provide the UNC path of the items. For example, here we are going to copy a file from the local computer to a remote computer called Test-PC.
Copy-Item D:\Temp\PowerShellcommands.csv -Destination \Test- PC\Sharedpath\PScommands.ps1 -PassThru
Here, file PowerShellcommands.csv is copied to the remote computer and renamed it with PSCommands.ps1
You can also copy files from the one shared location to another shared location.
Copy-Item \Test-PC1\D$\PowerShellcommands.csv -Destination \Test- PC\Sharedpath\PScommands.ps1 -PassThru
There is another way to copy items to the remote location is, you can use the ToSession parameter. To use the ToSesssion parameter, you need to connect a remote computer using PSRemote computer session and if destination files/folder is in the different domain or the workstation then you need to use the different credentials while remoting.
$destsession = New-PSSession -ComputerName Test-PC -Credential (Get-Credential) Copy-Item D:\Temp\PowerShellcommands.csv -ToSession $destsession -PassThru
You can also copy folder(s) with the same method described above.
$destsession = New-PSSession -ComputerName Test-PC -Credential (Get-Credential) Copy-Item D:\Temp\* -ToSession $destsession -Force -PassThru
You can also copy files from the one session to another session with the source path should mention with –FromSession parameter, while the destination path should mention with –ToSession parameter.
$destsession = New-PSSession -ComputerName Test-PC -Credential (Get-Credential) $sourcesession = New-PSSession -ComputerName Test1-PC -Credential (Get-Credential) Copy-Item -FromSession $sourcesession -ToSession $destsession -PassThru
- How to copy readonly and hidden files/folders in the PowerShell?
- How to display files/folders including hidden files/folders in PowerShell?
- How to test the shared location path from the remote computer in PowerShell?
- How to retrieve files and folders attributes using PowerShell?
- How to change files and folders attributes using PowerShell?
- How to get hidden files and folders using PowerShell?
- How to Zip / Unzip files or folders using PowerShell?
- How to delete empty files and folders using PowerShell?
- How to delete hidden files and folders using PowerShell?
- How to get only hidden files and folders in PowerShell?
- How to copy multiple files in PowerShell using Copy-Item?
- How to copy files with the specific extension in PowerShell?
- How to copy items from one location to another location using PowerShell?
- How to get only folders but not the files in the Get-ChildItem in PowerShell?
- How to copy files of the specific extension using PowerShell?