locked
Powershell - command works in PSSession not Invoke-Command? RRS feed

  • Question

  • I am just starting in learning PowerShell and in trying some things out I came across something I have been unsuccessful at finding a explanation to.

    I have a service that needs to be shutdown though a web link to a local host. If I am running from the server itself or establish a PSSession I can successfully stop the service running "Start http://localhost:9002/action=stop" but if I try using "invoke-command -computername ServerName {Start http://localhost:9002/action=stop}" The scrip appears to complete, no error message, but the service remains running. I am unsure if I am missing something in the command line our if this is something that just cannot be done?

    Tuesday, October 10, 2017 3:33 PM

All replies

  • Second hop restriction.  You also cannot run IE in a non-interactive session.

    You can try Invoke-WebRequest which does not use IE or a browser to execute the URL.


    \_(ツ)_/


    Tuesday, October 10, 2017 3:40 PM
  • Hi Steven,
    Please try below command.
    I have modified the command as per your requirement, just change the "RemoteComputer" part to the server that you are trying to run the command to and do let me know how it goes.

    $RemoteComputer = New-PSSession -ComputerName RemoteComputer
    Invoke-Command -Session $RemoteComputer {(Invoke-WebRequest "http://localhost:9002/action=stop")}

    Regards,
    Apps4rent_Anantesh
    Tuesday, October 10, 2017 11:02 PM
  • Hi Steven,
    I was curious to know if you had a chance to test out the script that i had given you in my earlier post.
    Do let me know how it goes with the script and incase if you need any further help.

    Regards,
    Apps4rent_Anantesh
    Thursday, October 12, 2017 9:38 PM