PowerShell script with credentials to copy file from one server to another server.
I have written the code but it's not working. What is wrong with my code? I get the error as
New-PSSession : myComp1 Connecting to remote server myComp1 failed with the following error message : The WS-Management service cannot process the request. Cannot find the Microsoft.PowerShell session configuration in the WSMan: drive on the myComp1 computer. For more information, see the about_Remote_Troubleshooting Help topic.
$pw = ConvertTo-SecureString -AsPlainText -Force -String password
$creds = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList "domain\UserName", $pw
$trgtSession = New-PSSession -ComputerName myComp1 -Credential $creds
Copy-Item -ToSession $trgtSession -Path "C:\Users\" -Destination "C:\Users\desktop\" -Recurse
Expected result: code to move the file from one server to another server with credentials.