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

x
?
Solved

C# / PowerShell WebAdministration Module

Posted on 2012-09-18
2
Medium Priority
?
665 Views
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();

         psObj.AddCommand("Invoke-Command");
         psObj.AddArgument(@"Full.Computer.Name");
         psObj.AddCommand("Import-Module");
         psObj.AddParameter("WebAdministration");
         psObj.AddCommand("Stop-Website");
         psObj.AddParameter("MyWebsite");
         psObj.Invoke();

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.
0
Comment
Question by:Puzzled_Dev
2 Comments
 

Accepted Solution

by:
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.
$psObj.stop_website

Open in new window

0
 

Author Comment

by:Puzzled_Dev
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.
0

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