search
Categories
Sponsors
VirtualMetric Hyper-V Monitoring, Hyper-V Reporting
Archive
Blogroll

Badges
MCSE
Community

Cozumpark Bilisim Portali
Posted in Windows Powershell | 2 Comments | 8,526 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:

Get-WmiObject -Class "Win32_PerfFormattedData_PerfProc_Process"

If you run this on PowerShell, you will notice that it will takes for a while. So lets run same query with CIM:

Get-CimInstance -Class "Win32_PerfFormattedData_PerfProc_Process" -OperationTimeoutSec 15

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.