简体   繁体   English

Powershell - 导出为CSV问题

[英]Powershell - Exporting to CSV question

I'm trying to export just the numerical value for two performance counters to CSV. 我正在尝试将两个性能计数器的数值导出为CSV。 I've been able to get 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: 我的csv最终看起来像:

"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. 将-expandproperty参数添加到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/ 这是关于该参数的博客文章: http//powershellstation.com/2009/11/11/an-overlooked-parameter/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM