How to Use PowerShell’s Invoke-WMIMethod
If you have not already done so, click open Windows PowerShell ISE.
The first thing we will do is make sure those particular windows features are turned off. In this particular tutorial we use W3SVC so in your start menu, type in Windows Features and you will have a small window pop up where you can choose by check box, the features you want on or off. Select web management tools and everything under World Wide Web Services, you may have to scroll down a bit.
Your window should appear like the following image:
Methods are code blocks that are designed to perform a special action. You can actually run the following command:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<form id="form1" runat="server">
You use the –path parameter to specify an instance of the Win32_Service class to run the method on. In the above command it tells it to run against the Win32_Service instance where the Name property is equal to W3SVC.
The output is presented as the following:
At times, methods require arguments to be specified so that it knows what to do. An excellent example is the Create method for the Win32_Process class. This method is used to create a new process, but in order for it to do so, it needs the name of the executable that is to be run.
An example of this command being run is presented below:
protected void Page_Load(object sender, EventArgs e)
string strMessage = "Welcome to the Page_Load method!";
The output is presented within the console as well as with internet explorer launching, as presented below:
A Few Last Words
There are various applications to today’s lesson, just keep in mind that in order to run various commands and scripts in PowerShell, you must have administrative rights. Thank you for being a valued reader. Join us next time for additional Windows PowerShell tutorials! Till then…