2015-12-15 25 views
1

我正在运行以下代码来运行perfmon计数器,但无法在其Receive-Job输出上运行Export-Counter -Path $DestinationFile -FileFormat csv您可以将作业中的计数器导出为CSV吗?

Start-Job -Name GettingCounters -ScriptBlock { 
    Get-Counter -Counter "\Processor(_total)\% Processor Time" -SampleInterval 1 -MaxSamples 120 
} 
$i = 0 
$duration = 120 
while ((Get-Job GettingCounters).State -eq 'Running') { 
    #increment 
    $i++ 

    #Round the numbers up for a nice output and then Write-Progress 
    Write-Progress -Activity "Processing $user" -PercentComplete (($i/$duration)*100) -Status ("Gathering data...") 
    Start-Sleep -Seconds 1 
} 

回答

1

如何不使用“导出柜台”,而是“出口-CSV”

Start-Job -Name GettingCounters -ScriptBlock { 
    Get-Counter -Counter "\Processor(_total)\% Processor Time" -SampleInterval 1 -MaxSamples 3 
} 

while ((Get-Job GettingCounters).State -eq 'Running') { 
    Start-Sleep -Seconds 1 
} 

$job = Get-Job GettingCounters |Receive-Job 

# better Format-Table? 
$job |Select-Object PSComputerName, Timestamp, @{Label='Readings'; Expression={$_.Readings.trim()}} |Export-Csv -Path test 

# lousy cleaning 
Get-Job |Remove-Job 

或另外,如果你没有远程运行它,而不是用工作吗?

与远程“对象”工作似乎有点棘手,我

但是,反序列化对象是不是活的对象。它是当前对象在序列化时的快照,它包含属性 但没有方法。您可以在Windows PowerShell中使用和管理这些对象, 包括在流水线中传递它们,显示选定的属性,以及格式化它们的 。

about_Remote_Output

相关问题