Reading SQL Performance Counters using PowerShell script
2
votes
2
answers
2488
views
I'm trying create a PS script to read some performance counter about my SQL for my Level 1 partners but I'm having a problem with the instance name.
I'm using this code:
$computer = "\\\" + $ENV:Computername
$instance = $computer + '\MSSQL$SG25DB'
write-Host $instance
Write-Output -InputObject "Use of Memory Buffer. The expected value must be greater than 80."
Get-Counter "$instance:Buffer Manager\Buffer cache hit ratio"
and the output is:
\\\\[hostname]\\MSSQL$SG25DB <--- Here appears the proper value :)
Use of Memory Buffer. The expected value must be greater than 80.
Get-Counter : The specified counter path could not be interpreted. At
line:5 char:12
+ Get-Counter <<<< "$instance:Buffer Manager\Buffer cache hit ratio"
+ CategoryInfo : InvalidResult: (:) [Get-Counter], Exception
+ FullyQualifiedErrorId : CounterApiError,Microsoft.PowerShell.Commands.GetCounterCommand
I have verified with Write-Host that the value of variable $instance is properly constructed but when I apply it to the Get-Counter command its fails. Do you have any idea? Could be related with the special character $? How can I make run it properly?
Asked by Simkin
(29 rep)
Jul 15, 2013, 04:30 PM
Last activity: Mar 10, 2021, 02:46 PM
Last activity: Mar 10, 2021, 02:46 PM