LF4*_*LF4 4 windows powershell performance
我不知道如何使用列表从系统中记录多个指标。该$CounterList变种不工作,但该$CounterList_Working变种一样。我见过根据路径获取列表的示例,例如(Get-Counter -List Processor(*)).Paths.
我以为我可以在变量中指定路径,但这不起作用。
什么是错的$CounterList在PowerShell脚本?我收到的错误消息是“Get-Counter:在计算机上找不到指定的对象。”。这让我认为它试图将列表作为单个值读取。
$CounterList = "\Network Interface(*)\Packets/sec
\Network Interface(*)\Current Bandwidth
\Network Interface(*)\Bytes Total/sec
\Memory\Committed Bytes
\Memory\Commit Limit"
$CounterList_Working = "\Processor(*)\% Processor Time"
echo "Gathering system data and writing to file $home\system_metrics.blg"
Get-Counter -Counter $CounterList -SampleInterval 2 -MaxSamples 10 | Export-counter -Path $home\system_metrics.blg
Run Code Online (Sandbox Code Playgroud)
根据Get-Counter的MSDN,参数 ...
-柜台
将来自指定性能计数器的数据指定为字符串数组。输入一个或多个计数器路径。您还可以将计数器路径字符串通过管道传输到此 cmdlet。
您正在使用单个字符串,这对于单个计数器来说很好。您的多个计数器列表需要一个数组。
$CounterList = "\Network Interface(*)\Packets/sec",
"\Network Interface(*)\Current Bandwidth",
"\Network Interface(*)\Bytes Total/sec",
"\Memory\Committed Bytes",
"\Memory\Commit Limit"
Run Code Online (Sandbox Code Playgroud)
应该像声明字符串数组的许多其他方法一样做到这一点。
如果出于某种疯狂的原因,您确实在使用换行符分隔的字符串,则可以将其转换为带有-split. 以下内容将提供与我的第一个示例相同的结果。
$CounterList = "\Network Interface(*)\Packets/sec
\Network Interface(*)\Current Bandwidth
\Network Interface(*)\Bytes Total/sec
\Memory\Committed Bytes
\Memory\Commit Limit" -split "`r`n"
Run Code Online (Sandbox Code Playgroud)
但是,如果您对此有任何控制权,我会选择以前的声明。
| 归档时间: |
|
| 查看次数: |
1206 次 |
| 最近记录: |