Chapter 16. Building your own WMI-based cmdlets

 

Richard Siddaway

Windows 8 and Windows Server 2012 come with a mass of new PowerShell functionality. Depending on the features installed the server version may have 2,500 or more new cmdlets! Did you know that of that of those 2,500 cmdlets, more than 60 percent are based on Windows Management Instrumentation (WMI)? This chapter explains how you can create your own WMI-based cmdlets.

Discovering WMI-based cmdlets

On a Windows 8 or Windows Server 2012 system try this:

PS> Get-ChildItem -Path $pshome\modules\netTCPIP

    Directory: C:\Windows\System32\WindowsPowerShell\v1.0\modules\netTCPIP

Mode                LastWriteTime     Length Name
----                -------------     ------ ----
d----        26/08/2012     14:40            en-US
-a---        02/06/2012     15:32      19097 MSFT_NetIPAddress.cdxml
-a---        02/06/2012     15:32      22334 MSFT_NetIPInterface.cdxml

-a---        17/06/2012     17:08       1979 NetTCPIP.psd1
-a---        02/06/2012     15:32      58379 Tcpip.Format.ps1xml
-a---        02/06/2012     15:32      42813 Tcpip.Types.ps1xml

Display abbreviated for brevity.

The last three files are standard module files (manifest, format, and types, respectively)—nothing exciting there. But notice the extension on the first two files: cdxml. That’s new!

Now look in the file:

Creating a WMI-based cmdlet

Using a WMI-based cmdlet

Adding extra filter parameters

Creating cmdlets from WMI methods

Summary

About the author

sitemap