PowerShell Invoke-Command gives Access Denied Error

Priem Matisse 21 Reputation points
2022-07-13T14:29:52.177+00:00

I'm trying to run a script that lists all the printers connected to the PCs on my network. I created a Shared Folder on PC1 and am trying to connect to PC2 from PC2, using "Invoke-Command -ComputerName PC1 -FilePath \SharedFolder\SubFolder\Script" . Whenever I do this, PC2 is unable to access the shared folder, even though it has access in the Explorer. I have enabled PSRemoting on PC2. Does anyone know a fix?

Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,462 questions
0 comments No comments
{count} votes

Accepted answer
  1. Rich Matheisen 45,906 Reputation points
    2022-07-13T15:08:39.537+00:00

    Is it safe to assume that you're running the Invoke-Command from a machine that isn't PC1 or PC2?

    If that's true you've encountered the "second hop" problem: ps-remoting-second-hop

    If, on the other hand, you're running the Invoke-Command from PC1 then there's no need for the "-ComputerName PC1" -- but you still have the "second hop" problem because you cannot use the credentials from PC1 to access the shared directory on PC1 from PC2.


1 additional answer

Sort by: Most helpful
  1. Aung Zaw Min Thwin 306 Reputation points
    2022-07-14T04:39:52.323+00:00

    What is the path you used from PC2 in explorer? Is it "\pc1\SharedFolder\SubFolder\Script"?