共用方式為


Export-Counter

將性能計數器數據匯出至記錄檔。

語法

Default (預設值)

Export-Counter
    [-Path] <String>
    [-FileFormat <String>]
    [-MaxSize <UInt32>]
    -InputObject <PerformanceCounterSampleSet[]>
    [-Force]
    [-Circular]
    [<CommonParameters>]

Description

Export-Counter Cmdlet 會將性能計數器數據(PerformanceCounterSampleSet 物件)導出至二進位效能記錄檔 (.blg)、逗號分隔值 (.csv), 或製表符分隔值 (.tsv) 格式的記錄檔。 您可以使用此 Cmdlet 來記錄性能計數器數據。

Export-Counter Cmdlet 的設計目的是匯出 Get-Counter 和 Import-Counter Cmdlet 所傳回的數據。

此 Cmdlet 只會在 Windows 7、Windows Server 2008 R2 和更新版本的 Windows 上執行。

範例

範例 1:將計數器數據匯出至檔案

PS C:\> Get-Counter "\Processor(*)\% Processor Time" | Export-Counter -Path $home\Counters.blg

此命令會將計數器數據匯出至 BLG 檔案。

命令會使用 Get-Counter Cmdlet 來收集處理器時間數據。 它會使用管線運算符 (|) 將數據傳送至 Export-Counter Cmdlet。 Export-Counter 命令會使用 Path 變數來指定輸出檔。

由於數據集可能非常大,此命令會透過管線將數據傳送至 Export-Counter。 如果資料儲存在變數中,命令可能會使用不成比例的記憶體數量。

範例 2:將檔案匯出至計數器檔格式

The first command uses the built-in Windows PowerShell conversion feature to store the value of 1 gigabyte (GB) in bytes in the $1GBInBytes variable. When you type a value followed by K (kilobyte), MB (megabyte), or GB, Windows PowerShell returns the value in bytes.
PS C:\> $1GBInBytes = 1GB

The second command uses the Import-Counter cmdlet to import performance counter data from the Threads.csv file. The example presumes that this file was previously exported by using the **Export-Counter** cmdlet. A pipeline operator (|) sends the imported data to the **Export-Counter** cmdlet. The command uses the *Path* parameter to specify the location of the output file. It uses the *Circular* and *MaxSize* parameters to direct the **Export-Counter** cmdlet to create a circular log that wraps at 1 GB.
PS C:\> Import-Counter Threads.csv | Export-Counter -Path ThreadTest.blg -Circular -MaxSize $1GBinBytes

此範例會將 CSV 檔案轉換成計數器數據 BLG 格式。

範例 3:從遠端電腦取得計數器數據,並將數據儲存至檔案

The first command uses the Get-Counter cmdlet to collect working set counter data from Server01, a remote computer. The command saves the data in the $C variable.
PS C:\> $C = Get-Counter -ComputerName Server01 -Counter "\Process(*)\Working Set - Private" -MaxSamples 20

The second command uses a pipeline operator (|) to send the data in $C to the **Export-Counter** cmdlet, which saves it in the Workingset.blg file in the Perf share of the Server01 computer.
PS C:\> $C | Export-Counter -Path \\Server01\Perf\WorkingSet.blg

此範例示範如何從遠端電腦取得性能計數器數據,並將數據儲存在遠端電腦上的檔案中。

範例 4:重新記錄現有的數據

The first command uses the **Import-Counter** cmdlet to import performance counter data from the DiskSpace.blg log. It saves the data in the $All variable. This file contains samples of the "LogicalDisk\% Free Space" counter on more than 200 remote computers in the enterprise.
PS C:\> $All = Import-Counter DiskSpace.blg

The second command uses the **CounterSamples** property of the sample set object in $All and the Where-Object cmdlet (alias = "where") to select objects with **CookedValues** of less than 15 (percent). The command saves the results in the $LowSpace variable.
PS C:\> $LowSpace = $All.CounterSamples | where {$_.CookedValues -lt 15}

The third command uses a pipeline operator (|) to send the data in the $LowSpace variable to the **Export-Counter** cmdlet. The command uses the *Path* parameter to indicate that the selected data should be logged in the LowDiskSpace.blg file.
PS C:\> $LowSpace | Export-Counter -Path LowDiskSpace.blg

此範例示範如何使用 Import-Counter 和 Export-Counter Cmdlet 重新記錄現有數據。

參數

-Circular

表示輸出檔是循環記錄檔,第一個是先出 (FIFO) 格式。 當您包含此參數時,需要 MaxSize 參數。

參數屬性

類型:SwitchParameter
預設值:False
支援萬用字元:False
不要顯示:False

參數集

(All)
Position:Named
必要:False
來自管線的值:False
來自管線按屬性名稱的值:False
來自剩餘引數的值:False

-FileFormat

指定輸出記錄檔的輸出格式。

此參數可接受的值為:

  • CSV
  • TSV
  • BLG

預設值為 BLG。

參數屬性

類型:String
預設值:BLG
支援萬用字元:False
不要顯示:False

參數集

(All)
Position:Named
必要:False
來自管線的值:False
來自管線按屬性名稱的值:False
來自剩餘引數的值:False

-Force

如果現有檔案存在於 Path 參數所指定的位置,則覆寫並取代現有的檔案。

參數屬性

類型:SwitchParameter
預設值:False
支援萬用字元:False
不要顯示:False

參數集

(All)
Position:Named
必要:False
來自管線的值:False
來自管線按屬性名稱的值:False
來自剩餘引數的值:False

-InputObject

指定要匯出的計數器數據,做為陣列。 輸入包含數據或取得數據的命令變數,例如 Get-CounterImport-Counter Cmdlet。

參數屬性

類型:

PerformanceCounterSampleSet[]

預設值:None
支援萬用字元:False
不要顯示:False

參數集

(All)
Position:Named
必要:True
來自管線的值:True
來自管線按屬性名稱的值:True
來自剩餘引數的值:False

-MaxSize

指定輸出檔的大小上限。

如果指定 Circular 參數,則當記錄檔達到指定的大小上限時,系統會刪除最舊的專案,因為新增了較新的專案。 如果未指定 Circular 參數,則當記錄檔達到指定的大小上限時,就不會新增任何新數據,而且 Cmdlet 會產生非終止錯誤。

參數屬性

類型:UInt32
預設值:None
支援萬用字元:False
不要顯示:False

參數集

(All)
Position:Named
必要:False
來自管線的值:False
來自管線按屬性名稱的值:False
來自剩餘引數的值:False

-Path

指定輸出檔的路徑和檔案名。 在本機計算機上輸入相對或絕對路徑,或遠端計算機的統一命名慣例 (UNC) 路徑,例如 \\Computer\Share\file.blg。 這是必要參數。

檔格式是由 FileFormat 參數的值所決定,而不是路徑中的擴展名。

參數屬性

類型:String
預設值:None
支援萬用字元:False
不要顯示:False
別名:PSPath

參數集

(All)
Position:0
必要:True
來自管線的值:False
來自管線按屬性名稱的值:True
來自剩餘引數的值:False

CommonParameters

此 Cmdlet 支援一般參數:-Debug、-ErrorAction、-ErrorVariable、-InformationAction、-InformationVariable、-OutBuffer、-OutVariable、-PipelineVariable、-ProgressAction、-Verbose、-WarningAction 和 -WarningVariable。 如需詳細資訊,請參閱 about_CommonParameters

輸入

PerformanceCounterSampleSet

您可以使用管線將性能計數器數據從 Get-CounterImport-Counter 傳送至此 Cmdlet。

輸出

None

備註

  • 記錄檔產生器預期所有輸入物件具有相同的計數器路徑,而且物件會以遞增的時間順序排列。

    第一個輸入物件的計數器類型和路徑會決定記錄檔中記錄的屬性。 如果其他輸入對象沒有記錄屬性的值,則屬性欄位是空的。 如果物件具有未記錄的屬性值,則會忽略額外的屬性值。

    性能監視器可能無法讀取 導出計數器 產生的所有記錄。 例如,性能監視器要求所有物件都有相同的路徑,而且所有物件都以相同的時間間隔分隔。

    Import-Counter Cmdlet 沒有 ComputerName 參數。 不過,如果計算機設定為遠端 Windows PowerShell Windows PowerShell,您可以使用 Invoke-Command Cmdlet 在遠端電腦上執行 Import-Counter 命令。