Invoke-command with IIS


This topic contains 2 replies, has 2 voices, and was last updated by Profile photo of Manfred Manfred 11 months, 2 weeks ago.

  • Author
  • #31755
    Profile photo of Manfred

    I've got a question. I'm a noob with powershell and I'm trying to restart (stop and later start) a webpage. In the local Powershell I run the "Stop-WebSite " " and it works. However when I try to run remotely with invoke-command it fails. Remoting is allowed on the IIS server. This is my command and the result I get:

    Invoke-Command -Session $session -ScriptBlock $block -ArgumentList $siteName
    The term 'Stop-WebSite' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path
    is correct and try again.
        + CategoryInfo          : ObjectNotFound: (Stop-WebSite:String) [], CommandNotFoundException
        + FullyQualifiedErrorId : CommandNotFoundException
        + PSComputerName        : us-mn-dc-iis-d1

    I have IIS installed locally (so I have the PS Module). I'm on Win10, server is Win2008.


    Thank you.

  • #31762
    Profile photo of Paul Johnston
    Paul Johnston

    You need to import the WebAdministration module first.

    By default, server 2008 runs Powershell v2 and Windows 10 runs Powershell v5. From v3 and upwards, modules are imported 'on the fly' by Powershell as and when you need them. Pre v3, you need to tell Powershell to load the modules before you can use the cmdlets within them. When you use Invoke-Command you're essentially running the command with the version of Powershell installed on the remote computer, v2 in this case. Hopefully that clears things up a little.

  • #31765
    Profile photo of Manfred

    You're a genius! It worked like a charm! Thank you so much.

    Have a great weekend!

You must be logged in to reply to this topic.