0
votes

I notice an error " Connecting to remote server usa-chicago failed with the following error message : Access is denied. For more information, see the about_Remote_Troubleshooting Help topic

  • CategoryInfo : OpenError: (usa-chicago:String) [], PSRemotingTransportException
    • FullyQualifiedErrorId : AccessDenied,PSSessionStateBroken

". Below is the snippet used. Any suggestions?

All the machines are inside a workgroup.

$computers = gc "C:\servers.txt"
$source = "\\usa-chicago\c$\temp\one.jar"
$destination = "c$\july1\folder1\"

foreach ($computer in $computers) {
        Invoke-Command -Computername $computer -ScriptBlock  { & Copy-Item $using:source -Destination \\$using:computer\$using:destination -Force } 
 
}
1
Sure the Destination is c$ not c:\ ?T-Me
I found that sometimes the service on the computer that is invoking the command is in a kind of sleep state and will produce this error stating that the destination is not responding. If that is the case executing the code twice works for me. The first execution errors out and the second gets executed... Best used in try{}catch{}T-Me
And just to be sure: Enable-PSRemoting was executed on the target? ;)T-Me
yes it is enabledGeorge

1 Answers

0
votes

Does your user account have access both to the computer and also the share you try to copy something to? It could be that you hit the dreaded 'second hop' problem with PowerShell Remoting: https://docs.microsoft.com/en-us/powershell/scripting/learn/remoting/ps-remoting-second-hop?view=powershell-7

If this is the problem, there are some workarounds for that. What i like to do is: In the Invoke Command, create a Scheduled Task with the commands you'd like to execute and pass the credentials into it, execute it, and delete it after.