Execute powershell script remotely

I would like to run the following script from my workstation and have it execute on the remote IIS web server by providing the IP address of the web server.

My code looks something like this and returns the name of a site and the state.

$iis =  (New-Object Microsoft.Web.Administration.ServerManager).Sites
     [string] $OutFile = "C:\WebState.txt"
     [string] $host2 = [System.Net.Dns]::GetHostName()
     Write-Host $host2
     foreach($MySite in $iis)
       $MySite.Name + ":" + $MySite.State  | Out-File $OutFile -append

How do I run this script local and have it execute on my remote web server?
Who is Participating?
Brad HoweDevOps ManagerCommented:
What version of Powershell are you using?

With Powershell V2, you can use it's remoting capabilities and have the script run locally and call the server remotely.


It is based on Windows Remote Management (WinRM).


wademiAuthor Commented:
So this cannot be done in Pwershell V1?
Brad HoweDevOps ManagerCommented:
Unfortunately not. WinRM was only introduced in PSv2.

  - Hades666
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.