Man*_*jot 9 sql-server powershell
我正在编写一个 powershell 脚本来捕获以下 SQL 服务器计数器:
SQL Server:内存管理器:总服务器内存 (KB)
SQL Server:内存管理器:目标服务器内存 (KB)
我的机器有 3 个 SQL 服务器实例,因此我希望此脚本动态捕获所有计数器并仅报告 1 个样本的值。我尝试编写以下内容:
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
Run Code Online (Sandbox Code Playgroud)
最终我想通过-computername
参数在多个服务器上运行它,因此我希望它动态捕获。
任何人都可以帮我找到缺少的东西吗?以下是我正在运行的确切脚本:
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)
}
Run Code Online (Sandbox Code Playgroud)
提前致谢
小智 7
Aaron Bertrand 在其上写了一篇非常详细的好帖子...我如何使用 PowerShell 收集性能计数器数据。
然后,Laerte Junior 在一篇简单的文章中详细介绍了他如何找到他想要的计数器:使用 Powershell 收集性能数据。这可能是您想要开始的地方。它有一些他用来捕获我相信的特定实例的计数器的 cmdlet。
看看这是不是你需要的:
$listofmetrics = (Get-Counter -ListSet "*Databases" -ComputerName $hostname).Counter | Where {$_ -like "*\Transactions/sec"}
$listofmetrics | Get-Counter
Run Code Online (Sandbox Code Playgroud)