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.



[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.Web.Administration")
     
$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?
wademiAsked:
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.

   http://msdn.microsoft.com/en-us/gg981612
   http://blogs.technet.com/b/josebda/archive/2010/03/31/experimenting-with-powershell-v2-remoting.aspx

It is based on Windows Remote Management (WinRM).

   http://msdn.microsoft.com/en-us/library/aa384426(VS.85).aspx


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

Sorry.
  - Hades666
0
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.