Learn how to a build a cloud-first strategyRegister Now

  • 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.

$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?
  • 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.


It is based on Windows Remote Management (WinRM).


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

  - Hades666

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