I am writing a powershell script to capture the following SQL server counters:
SQL Server: Memory Manager: Total Server Memory (KB)
SQL Server: Memory Manager: Target Server Memory (KB)
My machine has 3 instances of SQL servers, so I want this script to capture all counters dynamically and report the value for 1 sample only. i tried writing the following:
Get-counter -List *SQL*Memory* | Select paths, counter | format-list # doesn't display full list
Get-counter -List *SQL*Memory* | Select paths, counter | where {_.counter -like "*server memory*"} |format-list # displays nothing
eventually I want to run this across multiple servers with -computername
parameter and hence I want it to capture dynamically.
Can anyone please help me in finding what is missing? Following is the exact script that I am running:
Function checkTransactionsPerSecond([string] $Hostname )
{
(Get-Counter -ListSet "*Databases").Counter | Where {$_ -like "*\Transactions/sec"} #this returns nothing
# $listofmetrics = (Get-Counter -ListSet "*Databases").Counter | Where {$_ -like "*\Transactions/sec"}
# $listofmetrics | Get-Counter
}
clear
foreach ($Hostname in Get-Content "D:\TEMP\machines.txt")
{
Write-Host $Hostname
checkTransactionsPerSecond($Hostname)
}
thanks in advance