我正在设置一个可以从任何 Windows 服务器运行的脚本,以在滚动日志文件的后台收集一些 perfmon 脚本。我可以使用 PerfMon GUI,但我认为这会给我一个同时学习一些 Powershell 的好机会,并且我可以根据我的项目的具体需求将它们全部包装在我自己的简化 GUI 中。
基本上,该脚本验证 ExecutionPolicy 是否设置为 remotesigned(因此它可以运行),然后定义几个变量以在以下命令中使用,并概述要抓取的计数器。
之后,它将命令存储为变量,然后将其作为作业启动。问题是我从来没有以我要求的 .csv 文件的形式看到该工作的结果。这是代码:
Set-ExecutionPolicy remotesigned -Force
$Computer = $env:COMPUTERNAME
$1GBInBytes = 1GB
$p = "\\$Computer\Process(System)\% Processor Time",
"\\$Computer\PhysicalDisk(_Total)\Current Disk Queue Length",
"\\$Computer\PhysicalDisk(0 c:)\% Disk Time",
"\\$Computer\PhysicalDisk(0 c:)\Avg. Disk Queue Length",
"\\$Computer\PhysicalDisk(0 c:)\% Disk Read Time",
"\\$Computer\PhysicalDisk(0 c:)\Avg. Disk Read Queue Length",
"\\$Computer\PhysicalDisk(0 c:)\% Disk Write Time",
"\\$Computer\PhysicalDisk(0 c:)\Avg. Disk Write Queue Length",
"\\$Computer\PhysicalDisk(0 c:)\Avg. Disk sec/Transfer",
"\\$Computer\PhysicalDisk(0 c:)\Avg. Disk sec/Read",
"\\$Computer\PhysicalDisk(0 c:)\Avg. Disk sec/Write",
"\\$Computer\PhysicalDisk(0 c:)\Disk Transfers/sec",
"\\$Computer\PhysicalDisk(0 c:)\Disk Reads/sec",
"\\$Computer\PhysicalDisk(0 c:)\Disk Writes/sec",
"\\$Computer\PhysicalDisk(0 c:)\Disk Bytes/sec",
"\\$Computer\PhysicalDisk(0 c:)\Disk Read Bytes/sec",
"\\$Computer\PhysicalDisk(0 c:)\Disk Write Bytes/sec",
"\\$Computer\PhysicalDisk(0 c:)\Avg. Disk Bytes/Transfer",
"\\$Computer\PhysicalDisk(0 c:)\Avg. Disk Bytes/Read",
"\\$Computer\PhysicalDisk(0 c:)\Avg. Disk Bytes/Write",
"\\$Computer\PhysicalDisk(0 c:)\% Idle Time",
"\\$Computer\PhysicalDisk(0 c:)\Split IO/Sec";
$counter = {get-counter -counter $p -Continuous | Export-Counter C:\PerfLogs\Storage_BBCRM.csv -Force -FileFormat CSV -Circular -MaxSize $1GBInBytes}
Start-job $counter
有任何想法吗?现在,我想将该作业作为后台作业启动,我将通过单独的 powershell 命令停止它。我只是希望它把所有这些都变成一个 .csv。