Chapter 25. Working with WMI in PowerShell
PowerShell has the capability to work with all three of the major kinds of objects in Windows: .NET, COM, and WMI. Windows Management Instrumentation is a general method for managing Windows components and applications, both on the local machine and on other machines over the network.
The number of WMI objects available in current versions of Windows can seem bewildering at first. We won't try to list every available WMI object; rather, we'll look at how to discover what is available and make use of it in your own scripts.
First of all, WMI objects are arranged into namespaces. A namespace is a collection of related WMI objects. The objects belong to classes. And several instances may exist of each class.
Here's a simple case of getting the drives on the local computer:
> Get-WmiObject -namespace root\cimv2 -class win32_logicalDisk DeviceID : C: DriveType : 3 ProviderName : FreeSpace : 5735075840 Size : 99929288704 VolumeName :
DeviceID : D: DriveType : 5 ProviderName : FreeSpace : Size : VolumeName : DeviceID : E: DriveType : 2 ProviderName : FreeSpace : 106528768 Size : 1018822656 VolumeName :
As you can see, each Logical disk object has a DeviceID
—the drive letter, a Drivetype
—that indicates whether it is a hard disk, CD/DVD, and so on.
It is often necessary to look up information about the ...
Get Microsoft® PowerShell, VBScript and JScript® Bible now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.