Exploring PowerShell’s Get-WmiObject Cmdlet
Welcome back to Wahmans PowerShell blog! Today, we’re going to dive into a powerful cmdlet called Get-WmiObject. If you’ve ever needed to retrieve system information from local or remote computers, chances are you’ve encountered WMI (Windows Management Instrumentation). The Get-WmiObject cmdlet allows us to interact with WMI and extract detailed information about the system.
What does Get-WmiObject do?
According to Microsoft’s documentation: “Gets instances of Windows Management Instrumentation (WMI) classes or information about the available classes”. In simpler terms, it lets you query information about your Windows system hardware, OS details, services, and more – all using PowerShell!
Examples: From Beginner to Advanced
Let’s walk through four examples, arranged from beginner to more advanced use cases:
Example 1: Get Operating System Info
Get-WmiObject -Class Win32_OperatingSystem
This will return information about the operating system including the version, build number, registered user, and more.
Example 2: List Installed Services
Get-WmiObject -Class Win32_Service | Select-Object Name, State, StartMode
This command queries all services on your system, displaying the name, current state (Running/Stopped), and how they are set to start.
Example 3: Query a Remote Computer
Get-WmiObject -Class Win32_ComputerSystem -ComputerName "RemotePCName" -Credential (Get-Credential)
Here you query a remote computer for system information, using valid credentials. Super useful for sysadmins managing multiple machines!
Example 4: Monitor Disk Space with WMI Query Language (WQL)
$query = "SELECT * FROM Win32_LogicalDisk WHERE DriveType = 3 AND FreeSpace < 10737418240"
Get-WmiObject -Query $query | Select-Object DeviceID, FreeSpace, Size
This advanced example uses WQL to find all fixed drives (like C:) with less than 10GB of free space. Great for proactive disk monitoring scripts!
Wrapping Up
The Get-WmiObject cmdlet is a powerful tool with a wide variety of applications in systems administration and monitoring. Note that in PowerShell Core and newer scripting practices, Get-CimInstance is recommended as a more modern alternative, but Get-WmiObject is still relevant and widely used in traditional Windows environments.
Happy scripting, and I will see you in the next post!
Leave a Reply