Invoke-command with IIS

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.

Thoughts?

Thank you.

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.

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

Have a great weekend!