weird behavior of "Get-CimInstance"

Nico Eckstein 1 Reputation point
2021-07-13T10:25:34.197+00:00

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
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
12,774 questions
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,383 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Ian Xue (Shanghai Wicresoft Co., Ltd.) 30,281 Reputation points Microsoft Vendor
    2021-07-14T10:15:40.733+00:00

    Hi @Nico Eckstein

    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.