Hi,
I have noticed a quite weird behavior with Get-CimInstance where I don't know how it could be changed...
background for my problem: I want to regularly fetch SQL performancedata via a Powershell-script & WMI for a monitoring system
OS: Windows Server 2019
UAC activated
my user is member of the local admin-group
When I try to fetch data via Get-CimInstance in a normal Powershell session, I don't get any data back. Once I use the same PS-command in a admin-PS, I also get data back in my normal PS session, but only also for a limited time. Once I don't request data via Get-CimInstance for longer than 80 seconds, I can't fetch any data until I use Get-CimInstance again in my admin-PS session.
MSSQLINSTANCE and DBname need to be changed of course
loop to increment the interval with each run, this is running in my normal PS session:
for ($i=80;$i -le 120;$i=$i+5) {Get-Date; Get-CimInstance -ClassName Win32_PerfFormattedData_MSSQLINSTANCE_MSSQLINSTANCEDatabases | where-object { $_.Name -eq "DBname"}| Select Transactionspersec; Start-Sleep -s $i}
command in my admin PS session:
Get-Date; Get-CimInstance -ClassName Win32_PerfFormattedData_MSSQLINSTANCE_MSSQLINSTANCEDatabases | where-object { $_.Name -eq "DBname"}| Select Transactionspersec
I start the command in my admin PS, then directly afterwards I start the loop in my normal PS session.
Values are returned fine until the interval is getting longer than 80 seconds. Then Get-CimInstance just returns nothing.
Any idea what could cause this and how it could be fixed? Adding my user to local groups "Performance Log Users" and "Performance Monitor Users" did not change anything.
Update: tested the same on a Win SRV 2016 also with activated UAC, but there it is working as expected.