C# / PowerShell WebAdministration Module

Posted on 2012-09-18
Last Modified: 2012-09-25
Working with Power Shell you can run the following command.

Invoke-Command Full.Computer.Name {Import-Module WebAdministration; Stop-Website MyWebSite}

Open in new window

Trying to work with this namespace ...
using System.Management.Automation;
using System.Diagnostics;

Open in new window

Would like to use the PowerShell object to do something along the lines of

          PowerShell psObj = PowerShell.Create();


Open in new window

I'm not sure how to break down the commands and arguments for the PowerShell object.  
How would I transpose the command into the C# object.
Question by:Puzzled_Dev

    Accepted Solution

    With PowerShell you can create your objects of Object type and add Properties and functions to them. Unlike most programming languages, you can't create a class here, unless you use C# code. But this is how you can start with creating objects in powershell and add members to them.
    $psObj=New-Object -TypeName Object
    # Adding properties
    $psObj | Add-Member NoteProperty raw_capacity "20GB" -PassThru
    # Adding functions
    $psObj | Add-Member ScriptMethod stop_website{
    				$raw = $this.raw_capacity
                                    # Do something here
                                    return $return_value

    Open in new window

    Next you can use this object to invoke methods.

    Open in new window


    Author Comment

    my apologies for taking so long to reply to the post ... this is exactly what i needed to get started. Thank you very much.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Are you one of those front-line IT Service Desk staff fielding calls, replying to emails, all-the-while working to resolve end-user technological nightmares? I am! That's why I have put together this brief overview of tools and techniques I use in o…
    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 …
    Need more eyes on your posted question? Go ahead and follow the quick steps in this video to learn how to Request Attention to your question. *Log into your Experts Exchange account *Find the question you want to Request Attention for *Go to the e…
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…

    794 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

    16 Experts available now in Live!

    Get 1:1 Help Now