Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 587
  • Last Modified:

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?
0
wademi
Asked:
wademi
  • 2
1 Solution
 
Brad HoweCommented:
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 HoweCommented:
Unfortunately not. WinRM was only introduced in PSv2.

Sorry.
  - Hades666
0

Featured Post

 The Evil-ution of Network Security Threats

What are the hacks that forever changed the security industry? To answer that question, we created an exciting new eBook that takes you on a trip through hacking history. It explores the top hacks from the 80s to 2010s, why they mattered, and how the security industry responded.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now