In this guide, you will learn how to use PowerShell to test WMI connections on a local and remote computer.
These commands are useful to quickly test WMI. By default, the windows firewall blocks WMI inbound connections, I’ll show you which rule to enable in the firewall.
Test WMI on Local Computer
This command will use WMI to query the local computer for the operating system.
Get-WmiObject -query "SELECT * FROM Win32_OperatingSystem"
You can see below the command returned the operating system info for my computer.
Test WMI on Remote Computer
You can use the same command as above and just add the -ComputerName option.
In this example, I’m going to test the WMI connection to the remote computer PC1.
Get-WmiObject -query "SELECT * FROM Win32_OperatingSystem" -ComputerName PC1
Next, I’ll disable WMI in the firewall.
On PC1, I’m going to disable the rule “Windows Management Instrumentation (WMI-in) on the inbound rules.
Now when I run the WMI query to the remote computer the connection will fail because the firewall is blocking it.
This firewall rule is disabled by default. If you need to run WMI queries on remote computers you need to enable the “Windows Management Instrumentation (WMI-in)” rule.
Thanks, the hints helped me a lot
You are welcome!
Hello Everyone, thanks for sharing the steps above. I have an issue that I am hoping you guys can help with.
I am trying to connect to my secondary DC via wmi, however, after using the command as listed above I get an error stating “Get-WmiObject : Access denied. Can you advise how I’d go about resolving this error?
Appreciate the help.
I’ve got one for you to consider. I had a test that did two WMI queries in a script. one worked, one failed. investigation revealed the machine I was testing on was missing around 700 classes. (had around 500 while a functional machine had 1200), so it was lucky dip. If I query one of the classes that still existed, WMI would test as functional, if I used one that didn’t exist WMI came back as broken…
That is strange.