Invoking WMI methods in PowerShell

Thursday, December 16, 2010

In PowerShell V1 if we wanted to invoke a method, the Win32_Volume WMI Format method in the following example, we used a syntax like: PS > $vol = Get-WmiObject -Class Win32_Volume -Filter "DriveLetter='R:'" PS > $vol.Format(...) Note: The Win32_Volume class exists on Windows Server 2003 and above, on Windows XP this class is not available.   To determine the values we need to pass to the Format method we pipe the volume object to the Get-Member cmdlet and look at the method...

Get-WMIQualifierValue (revisited)

Monday, August 31, 2009

An updated version of my Get-WMIQualifierValue function. With this version you can query remote computers, specify the NameSpace of the class and also specify a property name to get just its values instead of all properties. Sample Usage: Get-WMIQualifierValue -Class Win32_LogicalDisk -ComputerName computer1 –Property StatusInfo   function Get-WMIQualifierValue {    param(       $Class=$(Throw “Parameter ‘Class’ cannot be empty”),       $ComputerName=".",       $NameSpace="ROOT\cimv2",       $Property="*"   )    if($PSVersionTable)   {      #PowerShell v2 detected      $wmi = Get-WmiObject meta_class -Filter "__Class = '$class'" -Amended  `     -ComputerName $ComputerName -Namespace $NameSpace   }    else   {      #PowerShell v1 detected     $wmi="\\$ComputerName\$($NameSpace):$class"      $wmi.psbase.options.useAmendedQualifiers=$true    }...
no comments

Exchange White Space

Thursday, August 13, 2009

A common posting on PowerShell newsgroups and forums from Exchange administrators is how to parse event id 1221 from the Exchange server application log file. A typical event message would look like: Event Type:  Information Event Source: MSExchangeIS Mailbox Store Event Category: General  Event ID: 1221 Date:  10/01/2009 Time: 13:27:31 User:  N/A Computer: SERVER Description: The database "First Storage Group\Mailbox Store (SERVER)" has 7.2 megabytes of free space after online defragmentation has terminated. Usual solutions are based on regular expressions to process the message description and extract the name of the database(s) and the number of free megabytes. The bellow...

Converting WMI dates in a pipeline

Sunday, June 14, 2009

  Get-WMIObject is one of the most used cmdlets in PowerShell and many of us system administrators use it on a daily basis to perform our day to day tasks. Often we need to get values of CIM_DATETIME properties from instances of a class. An example would be the Win32_OperatingSystem class (truncated property list): PS > $os = Get-WMIObject Win32_OperatingSystem PS > $os | Format-List * (...) Debug ...


Monday, January 5, 2009

When you create WQL queries for Get-WMIObject you sometimes need to know some property values in advance. A good example is when you want to query the event logs for a specific EventType, you cant do: PS > Get-WmiObject -class Win32_NTLogEvent -filter "EventType='error'"Get-WmiObject : Invalid query It yields an error because EventType expects a numeric value:PS > Get-WmiObject -class Win32_NTLogEvent -filter "EventType=1" So, how do you know which values to use? One way is to find them on MSDN. That was my main method, but not anymore. With Get-WMIQualifierValue you will get the value names and their corresponding numeric values for...
one comment

Webcast: Managing Hyper-V Virtual Machines with WMI and Windows PowerShell

Tuesday, June 17, 2008

  Start Date: Wednesday, July 02, 2008 8:00 AM Pacific Time (US & Canada)   Event Overview Before the beta release of Microsoft System Center Virtual Machine Manager 2008, there was only one option for automating management of Hyper-V virtual machines—Windows Management Instrumentation (WMI). In this webcast, you learn how to automate the most common management tasks, how to create a delegation model using Windows Authorization Manager, and where the power of WMI can pick up where Virtual Machine Manager leaves off. In addition, the Hewlett-Packard Windows Server 2008 Academy team shares their experience automating the deployment of 600...
no comments