开发者

Powershell - Exporting to CSV question

I'm trying to export just the numerical value for two performance counters to CSV. I've been able to get 开发者_JAVA百科something built together but I still need some assistance.

    $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

My csv ends up looking like:

 
   "Received","Sent"
   "@{CookedValue=2469610}","@{CookedValue=307718}"

I would prefer it to look like

 
   "Received","Sent"
   "2469610","307718"

Any suggestions on how I can get there?


Add the -expandproperty parameter to the select-object cmdlet.

excerpt:

$data1 = Get-Counter $counter1
$data1cooked = $data1.countersamples | Select-Object -expandproperty cookedvalue
$data2 = Get-Counter $counter2
$data2cooked = $data2.countersamples | Select-Object -expandproperty cookedvalue

Here's a blog post about that parameter: http://powershellstation.com/2009/11/11/an-overlooked-parameter/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜