question

NicoEckstein-8461 avatar image
0 Votes"
NicoEckstein-8461 asked NicoEckstein-8461 edited

weird behavior of "Get-CimInstance"

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}

114231-grafik.png

command in my admin PS session:

Get-Date; Get-CimInstance -ClassName Win32_PerfFormattedData_MSSQLINSTANCE_MSSQLINSTANCEDatabases | where-object { $_.Name -eq "DBname"}| Select Transactionspersec

114168-grafik.png

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.


sql-server-generalwindows-server-powershell
grafik.png (20.9 KiB)
grafik.png (14.7 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

IanXue-MSFT avatar image
0 Votes"
IanXue-MSFT answered IanXue-MSFT edited

Hi @NicoEckstein-8461

I tried to reproduce the issue in my lab but no luck. Do you see the same if you use another WMI class? It seems more a WMI issue to me.

Best Regards,
Ian Xue
============================================
If the Answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi Ian, thanks for your reply.

Just tested with some other classes, e.g. Win32_PhysicalMemory and CIM_PhysicalMemory. For these it is working normally.

Also tested again with Get-WmiObject for the original mentioned class, with same result as in my original post.

So it's somehow related to SQL Server and the performance counters. Or have you also tested with an MSSQL class?

I have also sysadmin permissions to the SQL instance, but this should not matter for WMI queries as far as I know.

0 Votes 0 ·

Hi,

I tested with some MSSQL classes using Get-CinInstance and Get-WmiObject but they all worked as expected. As it may be a SQL issue, you can add the SQL tags for better help.

1 Vote 1 ·