Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


C# / PowerShell WebAdministration Module

Posted on 2012-09-18
Medium Priority
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

pranavkojha earned 1160 total points
ID: 38435471
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

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

Featured Post

Making Bulk Changes to Active Directory

Watch this video to see how easy it is to make mass changes to Active Directory from an external text file without using complicated scripts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In previous parts of this Nano Server deployment series, we learned how to create, deploy and configure Nano Server as a Hyper-V host. In this part, we will look for a clustering option. We will create a Hyper-V cluster of 3 Nano Server host nodes w…
My attempt to use PowerShell and other great resources found online to simplify the deployment of Office 365 ProPlus client components to any workstation that needs it, regardless of existing Office components that may be needing attention.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
Screencast - Getting to Know the Pipeline

564 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