2015-12-15 30 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

相關問題