20.6. Querying Hardware Devices

The examples you have seen so far have dealt with software entities only: processes, services, and so on. WMI makes no distinction between hardware and software objects, and its tight integration with the Windows kernel allows it to manipulate all sorts of devices. We can use it to get information about different computers and their hardware configurations.

For example, we can get information about the currently installed hard drives by querying the available Win32_DiskDrive objects. Here is what I get on my system:

PS> gwmi -class Win32_DiskDrive Partitions : 2 DeviceID : \\.\PHYSICALDRIVE0 Model : ST3320620AS ATA Device Size : 320070320640 Caption : ST3320620AS ATA Device Partitions : 1 DeviceID : \\.\PHYSICALDRIVE1 ...

Get Pro Windows PowerShell 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.