我正在尝试将两个性能计数器的数值导出为CSV。我已经能够得到一些东西,但我仍然需要一些帮助。
$counter1 = "\\ygex01wal\SMTP Server(_total)\Messages Received Total" $counter2 = "\\ygex01wal\SMTP Server(_total)\Messages Sent Total" $data1 = Get-Counter $counter1 $data1cooked = $data1.countersamples | Select-Object cookedvalue $data2 = Get-Counter $counter2 $data2cooked = $data2.countersamples | Select-Object cookedvalue $object = New-Object PSObject add-member -InputObject $object Noteproperty 'Received' $data1cooked add-member -InputObject $object Noteproperty 'Sent' $data2cooked $object | Export-Csv c:\csv.csv -NoTypeInformation
我的csv最终看起来像:
"Received","Sent" "@{CookedValue=2469610}","@{CookedValue=307718}"
我希望它看起来像
"Received","Sent" "2469610","307718"
关于我如何到达那里的任何建议?
答案 0 :(得分:4)
将-expandproperty参数添加到select-object cmdlet。
摘录:
$data1 = Get-Counter $counter1
$data1cooked = $data1.countersamples | Select-Object -expandproperty cookedvalue
$data2 = Get-Counter $counter2
$data2cooked = $data2.countersamples | Select-Object -expandproperty cookedvalue
这是关于该参数的博文: http://powershellstation.com/2009/11/11/an-overlooked-parameter/