Execute powershell script remotely

Posted on 2011-10-11
Last Modified: 2012-06-22
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?
Question by:wademi
    LVL 30

    Accepted Solution

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


    Author Comment

    So this cannot be done in Pwershell V1?
    LVL 30

    Expert Comment

    by:Brad Howe
    Unfortunately not. WinRM was only introduced in PSv2.

      - Hades666

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    This script checks a path to see if a folder exists. If the folder does exist you will get output "The folder has previously been created. No action taken" If not it will create the folder. Then adds one user modify permission to the folder. It …
    Microsoft Windows Server Update Service (WSUS) is free for everyone, but it lacks of some desirable features like send an e-mail to the administrator with the status of all computers on the WSUS server. This article is based on my PowerShell script …
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    This video discusses moving either the default database or any database to a new volume.

    745 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now