PowerShell for Windows Admins

Sep 8 2011   2:46PM GMT

Quirks of Get-member and WMI objects

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

Tags:

I have been asked about discovering the methods available on a WMI object. I’ve mentioned the GetMethodParameters method a few times but it can be difficult to find.  Normally if we want to discover the methods on an object we would do this

Get-WmiObject Win32_Service | Get-Member -MemberType method

which gives this list

Change

ChangeStartMode

Delete

GetSecurityDescriptor

InterrogateService

PauseService

ResumeService

SetSecurityDescriptor

StartService

StopService

UserControlService

we will ignore the terminal services object that also appears

To dig into the underlying object we use .psbase (or Get-Member -MemberType method –View base)

(Get-WmiObject Win32_Service).psbase | Get-Member -MemberType method

gives us this list

Address

Clone

CopyTo

Equals

Get

GetEnumerator

GetHashCode

GetLength

GetLongLength

GetLowerBound

GetType

GetUpperBound

GetValue

Initialize

Set

SetValue

ToString

Note that the object type is System.Management.Automation.PSMemberSet

When we use Get-WmiObject we are looking at an instance of the WMI class. To look at the class itself

[wmiclass]”Win32_Service” | Get-Member -MemberType method

but this just shows a Create method

If we drop into the base object now

([wmiclass]”Win32_Service”).psbase | Get-Member -MemberType method

we get

Clone

CompareTo

CopyTo

CreateInstance

CreateObjRef

Delete

Derive

Dispose

Equals

Get

GetHashCode

GetInstances

GetLifetimeService

GetMethodParameters

GetPropertyQualifierValue

GetPropertyValue

GetQualifierValue

GetRelated

GetRelatedClasses

GetRelationshipClasses

GetRelationships

GetStronglyTypedClassCode

GetSubclasses

GetText

GetType

InitializeLifetimeService

InvokeMethod

Put

SetPropertyQualifierValue

SetPropertyValue

SetQualifierValue

ToString

Which shows the Method we want and a few other potentially interesting methods to test out.

 Comment on this Post

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when other members comment.

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

Share this item with your network: