locked
Struggling with invoke-command RRS feed

  • Question

  • Howdy -

    I'm running into a wall with invoke-command, and I could use a hand. Here's my setup:

    Win 10, PS v.5.1
    Firewall is completely off for all profiles
    Execution Policy: unrestricted
    PSRemoting enabled
    WinRM: Running

    I'm just trying to get invoke-command to work at the moment with this simple command:

    Invoke-Command -ComputerName localhost -ScriptBlock {get-service}

    But I get this error back:

    [localhost] Connecting to remote server localhost failed with the following error message : The client cannot connect
    to the destination specified in the request. Verify that the service on the destination is running and is accepting
    requests. Consult the logs and documentation for the WS-Management service running on the destination, most commonly
    IIS or WinRM. If the destination is the WinRM service, run the following command on the destination to analyze and
    configure the WinRM service: "winrm quickconfig". For more information, see the about_Remote_Troubleshooting Help
    topic.
        + CategoryInfo          : OpenError: (localhost:String) [], PSRemotingTransportException
        + FullyQualifiedErrorId : CannotConnect,PSSessionStateBroken

    I'm not sure what else I need to do to get Invoke-Command to do it's thing.

    For what it's worth, I've also tried this on a Win7 system with the same results. 

    Thoughts?

    Thursday, August 17, 2017 3:14 PM

Answers

  • Okay - I dug in a little further back and solved this.

    The problem was the GPO I built to enable the WinRM service throughout my domain. I had tried limiting the source of remote PS commands only to my workstation. When I enabled commands from anywhere, the invoke-command behaves as expected.

    I will sally forth and build my script. Later, I'll filter sources for PS commands. :)

    • Marked as answer by AJ Van Beest Thursday, August 17, 2017 3:46 PM
    Thursday, August 17, 2017 3:46 PM

All replies

  • I'm a little bit confused. You don't need remoting for localhost. Just run Get-Service at the console prompt. If you try to run this remotely on another computer you have to use an account with administrative rights on the remote machine.

    Grüße - Best regards

    PS:> (79,108,97,102|%{[char]$_})-join''

    Thursday, August 17, 2017 3:43 PM
  • Okay - I dug in a little further back and solved this.

    The problem was the GPO I built to enable the WinRM service throughout my domain. I had tried limiting the source of remote PS commands only to my workstation. When I enabled commands from anywhere, the invoke-command behaves as expected.

    I will sally forth and build my script. Later, I'll filter sources for PS commands. :)

    • Marked as answer by AJ Van Beest Thursday, August 17, 2017 3:46 PM
    Thursday, August 17, 2017 3:46 PM