How to avoid WMI query hangs in PowerShell
Posted in Windows Powershell | No Comment | 2,911 views | 15/06/2015 12:28
Some WMI queries may be effected from system performance, so queries may run very long times. In some cases, I see that wmi query hangs, so PowerShell script is not able to continue. In that cases, we should use timeout parameter.
Since CIM is the new method for us, we should go with CIM. For example this is our WMI query:
If you run this on PowerShell, you will notice that it will takes for a while. So lets run same query with CIM:
As you see, CIM and WMI query is almost same. But additionally I’ve added OperationTimeoutSec parameters to avoid from hangs. That gives us ability to cancel query if it takes more than 15 seconds. You can change it anytime you want.
Leave a Reply