【发布时间】:2013-11-14 22:15:04
【问题描述】:
$timeout = new-timespan -Minutes 1
$sw = [diagnostics.stopwatch]::StartNew()
$path = "d:\powershell\test.csv"
"Processor Load, Available Memory(MB), Max Memory(Bytes)" >> $path
while ($sw.elapsed -lt $timeout)
{
$a = gwmi -query "Select * from win32_processor"
$b = gwmi -query "Select * from win32_perfrawdata_perfOS_memory"
$c = gwmi -query "Select * from win32_physicalmemory"
$date = Get-Date -format s
$a.loadpercentage + "," + $b.availableMbytes + "," + $c.capacity >> $path
start-sleep -seconds 5
}
所以我只是想了解一下正在发生的事情。我不只是出于某种原因在 perfmon 中打开它。基本上我希望在提到的 CSV 文件中得到一个逗号分隔的输出。它适用于单个变量,但是当我尝试添加第二个变量或文本时,我收到以下错误。
Cannot convert value ", test" to type "System.Int32". Error: "Input string was not in a
correct format."
At D:\powershell\VDIPerfMon.ps1:14 char:21
+ $a.loadpercentage + <<<< ", test" >> $path
+ CategoryInfo : NotSpecified: (:) [], RuntimeException
+ FullyQualifiedErrorId : RuntimeException
我该如何解决这个问题?
【问题讨论】:
-
我使用 powershell 连接运算符
-j给出了一个简单的答案,但我建议使用哈希表创建自定义对象,然后将其发送到 Export-CSV
标签: powershell perfmon