PowerShell for Windows Admins

Dec 16 2013   2:20PM GMT

CDXML–adding search parameters

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

Last time you saw how to create a cmdlet from the Win32_NetWorkAdapterConfiguration class:

<?xml version=’1.0′ encoding=’utf-8’?>

<PowerShellMetadata xmlns=’http://schemas.microsoft.com/cmdlets-over-objects/2009/11′>

<Class ClassName=’ROOT\cimv2\Win32_NetworkAdapterConfiguration’>

<Version>1.0</Version>

<DefaultNoun>NetworkAdapterConfiguration</DefaultNoun>

<InstanceCmdlets>

<GetCmdletParameters DefaultCmdletParameterSet=’DefaultSet’>

</GetCmdletParameters>

</InstanceCmdlets>

</Class>

</PowerShellMetadata>

 

Now its time to add some parameters that can be used for searching. This will be equivalent to performing these actions:

 

Get-CimInstance -ClassName Win32_NetworkAdapterConfiguration -Filter “DHCPEnabled=’True'”

Get-CimInstance -ClassName Win32_NetworkAdapterConfiguration -Filter “IPEnabled=’True'”

Get-CimInstance -ClassName Win32_NetworkAdapterConfiguration -Filter “Index=0″

Get-CimInstance -ClassName Win32_NetworkAdapterConfiguration -Filter “InterfaceIndex=3″

 

Lets start by looking at the DHCPEnabled property

£> $class = Get-CimClass -ClassName Win32_NetworkAdapterConfiguration

£> $class.CimClassProperties[“DHCPEnabled”]

Name                            : DHCPEnabled

Value                             :

CimType                       : Boolean

Flags                              : Property, ReadOnly, NullValue

Qualifiers                      : {MappingStrings, read}

ReferenceClassName :

The parameter DHCPEnabled takes a Boolean value. At the moment I don’t want anything clever like pipeline input – just the ability to use a parameter

 

This requirement translates to:

<?xml version=’1.0′ encoding=’utf-8’?>

<PowerShellMetadata xmlns=’http://schemas.microsoft.com/cmdlets-over-objects/2009/11′>

<Class ClassName=’ROOT\cimv2\Win32_NetworkAdapterConfiguration’>

<Version>1.0</Version>

<DefaultNoun>NetworkAdapterConfiguration</DefaultNoun>

<InstanceCmdlets>

<GetCmdletParameters DefaultCmdletParameterSet=’DefaultSet’>

 

<QueryableProperties>

<Property PropertyName=”DHCPEnabled”>

<Type PSType = “System.Boolean”/>

<RegularQuery >

<CmdletParameterMetadata PSName=”DHCPEnabled” />

</RegularQuery>

</Property>

 

</QueryableProperties>

 

</GetCmdletParameters>

</InstanceCmdlets>

</Class>

</PowerShellMetadata>

 

The changes are defined by the <QueryableProperties> tags

<QueryableProperties>

 

Define the WMI property you are searching on

<Property PropertyName=”DHCPEnabled”>

Define the type of the data the parameter accepts

<Type PSType = “System.Boolean”/>

Define the query type – in this case a straight forward search

<RegularQuery >

 

Define the name you want the parameter to have – doesn’t have to match the WMI property name

<CmdletParameterMetadata PSName=”DHCPEnabled” />

</RegularQuery>

</Property>

 

</QueryableProperties>

You can use the changed cmdlet like this:

Get-NetworkAdapterConfiguration

Get-NetworkAdapterConfiguration -DHCPEnabled $true

Get-NetworkAdapterConfiguration -DHCPEnabled $false

 

The full syntax on the cmldet is:

Get-NetworkAdapterConfiguration [-DHCPEnabled <bool[]>]

[-CimSession <CimSession[]>] [-ThrottleLimit <int>]

[-AsJob] [<CommonParameters>]

 

The cmdlets over objects technology automatically adds these parameters:

-CimSession

-ThrottleLimit

-AsJob

-CommonParameters

 

Next time we’ll add the other search properties

 

 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.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

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: