共用方式為


Import-Counter

匯入性能計數器記錄檔,並建立 物件,代表記錄中的每個計數器範例。

語法

GetCounterSet (預設值)

Import-Counter
    [-Path] <String[]>
    [-StartTime <DateTime>]
    [-EndTime <DateTime>]
    [-Counter <String[]>]
    [-MaxSamples <Int64>]
    [<CommonParameters>]

ListSetSet

Import-Counter
    [-Path] <String[]>
    -ListSet <String[]>
    [<CommonParameters>]

SummarySet

Import-Counter
    [-Path] <String[]>
    [-Summary]
    [<CommonParameters>]

Description

Import-Counter Cmdlet 會從性能計數器記錄檔匯入性能計數器數據,併為檔案中的每個計數器範例建立物件。 PerformanceCounterSampleSet 物件,其所建立的物件與收集性能計數器數據時 Get-Counter 傳回的物件相同。

您可以從逗號分隔值 (.csv)、Tab 分隔值 (.tsv) 和二進位效能記錄檔 (.blg) 匯入數據。 如果您使用 .blg 檔案,您可以在每個命令中匯入最多 32 個檔案。 您可以使用 Import-Counter 的參數來篩選您匯入的數據。

除了 Get-Counter 和 Export-Counter Cmdlet,此功能可讓您在 Windows PowerShell 中收集、匯出、匯入、合併、篩選、操作及重新匯出性能計數器數據。

範例

範例 1:從檔案匯入所有計數器數據

$Data = Import-Counter -Path ProcessorData.csv

此命令會將 ProcessorData.csv 檔案中的所有計數器數據匯入$Data變數。

範例 2:從檔案匯入特定計數器數據

PS C:\> $I = Import-Counter -Path "ProcessorData.blg" -Counter "\\SERVER01\Processor(_Total)\Interrupts/sec"

此命令只會將 「Processor(_total)\Interrupts/sec」 計數器數據從 ProcessorData.blg 檔案匯入$I變數。

範例 3:從性能計數器選取數據,然後將它匯出至檔案

The first command uses **Import-Counter** to import all of the performance counter data from the ProcessorData.blg files. The command saves the data in the $Data variable.
PS C:\> $Data = Import-Counter .\ProcessorData.blg

The second command displays the counter paths in the $Data variable. To get the display shown in the command output, the example uses the Format-Table cmdlet to format as a table the counter paths of the first counter in the $Data variable.
PS C:\> $Data[0].CounterSamples | Format-Table -Property Path

Path
----
\\SERVER01\Processor(_Total)\DPC Rate
\\SERVER01\Processor(1)\DPC Rate
\\SERVER01\Processor(0)\DPC Rate
\\SERVER01\Processor(_Total)\% Idle Time
\\SERVER01\Processor(1)\% Idle Time
\\SERVER01\Processor(0)\% Idle Time
\\SERVER01\Processor(_Total)\% C3 Time
\\SERVER01\Processor(1)\% C3 Time

The third command gets the counter paths that end in "Interrupts/sec" and saves the paths in the $IntCtrs variable. It uses the Where-Object cmdlet to filter the counter paths and the ForEach-Object cmdlet to get only the value of the **Path** property of each selected path object.
PS C:\> $IntCtrs = $Data[0].Countersamples | Where-Object {$_.Path -like "*Interrupts/sec"} | ForEach-Object {$_.Path}

The fourth command displays the selected counter paths in the $IntCtrs variable.
PS C:\> $IntCtrs

\\SERVER01\Processor(_Total)\Interrupts/sec
\\SERVER01\Processor(1)\Interrupts/sec
\\SERVER01\Processor(0)\Interrupts/sec

The fifth command uses the **Import-Counter** cmdlet to import the data. It uses the $IntCtrs variable as the value of the *Counter* parameter to import only data for the counter paths in $IntCtrs.
PS C:\> $I = Import-Counter -Path .\ProcessorData.blg -Counter $intCtrs

The sixth command uses the Export-Counter cmdlet to export the data to the Interrupts.csv file.
PS C:\> $I | Export-Counter -Path .\Interrupts.csv -Format CSV

此範例示範如何從性能計數器記錄檔 (.blg) 選取數據,然後將選取的數據匯出至 .csv 檔案。 前四個命令會從檔案取得計數器路徑,並將其儲存在名為 $Data的變數中。 最後兩個命令會匯入選取的數據,然後只匯出選取的數據。

範例 4:顯示匯入計數器集合群組中的所有計數器路徑

The first command uses the *ListSet* parameter of the **Import-Counter** cmdlet to get all of the counter sets that are represented in a counter data file.
PS C:\> Import-Counter -Path ProcessorData.csv -ListSet *

CounterSetName     : Processor
MachineName        : \\SERVER01
CounterSetType     : MultiInstance
Description        :
Paths              : {\\SERVER01\Processor(*)\DPC Rate, \\SERVER01\Processor(*)\% Idle Time, \\SERVER01
\Processor(*)\% C3 Time, \\SERVER01\Processor(*)\% Interrupt Time...}
PathsWithInstances : {\\SERVER01\Processor(_Total)\DPC Rate, \\SERVER01\Processor(1)\DPC Rate, \\SERVER01
\Processor(0)\DPC Rate, \\SERVER01\Processor(_Total)\% Idle Time...}
Counter            : {\\SERVER01\Processor(*)\DPC Rate, \\SERVER01\Processor(*)\% Idle Time, \\SERVER01
\Processor(*)\% C3 Time, \\SERVER01\Processor(*)\% Interrupt Time...}

The second command gets all of the counter paths from the list set.
PS C:\> Import-Counter -Path ProcessorData.csv -ListSet * | ForEach-Object {$_.Paths}

\\SERVER01\Processor(*)\DPC Rate
\\SERVER01\Processor(*)\% Idle Time
\\SERVER01\Processor(*)\% C3 Time
\\SERVER01\Processor(*)\% Interrupt Time
\\SERVER01\Processor(*)\% C2 Time
\\SERVER01\Processor(*)\% User Time
\\SERVER01\Processor(*)\% C1 Time
\\SERVER01\Processor(*)\% Processor Time
\\SERVER01\Processor(*)\C1 Transitions/sec
\\SERVER01\Processor(*)\% DPC Time
\\SERVER01\Processor(*)\C2 Transitions/sec
\\SERVER01\Processor(*)\% Privileged Time
\\SERVER01\Processor(*)\C3 Transitions/sec
\\SERVER01\Processor(*)\DPCs Queued/sec
\\SERVER01\Processor(*)\Interrupts/sec

這個範例示範如何在匯入的計數器集合群組中顯示所有計數器路徑。

範例 5:從時間戳範圍匯入計數器數據

The first command lists in a table the time stamps of all of the data in the ProcessorData.blg file.
PS C:\> Import-Counter -Path ".\disk.blg" | Format-Table -Property Timestamp

The second command saves particular time stamps in the $Start and $End variables. The strings are cast to **DateTime** objects.
PS C:\> $Start = [datetime]"7/9/2008 3:47:00 PM"; $End = [datetime]"7/9/2008 3:47:59 PM"

The third command uses the **Import-Counter** cmdlet to get only counter data that has a time stamp between the start and end times (inclusive). The command uses the *StartTime* and *EndTime* parameters of **Import-Counter** to specify the range.
PS C:\> Import-Counter -Path Disk.blg -StartTime $start -EndTime $end

這個範例只會匯入在命令中所指定結束範圍之間具有時間戳的計數器數據。

範例 6:從性能計數器記錄檔匯入指定數目的最舊範例

The first command uses the **Import-Counter** cmdlet to import the first (oldest) five samples from the Disk.blg file. The command uses the *MaxSamples* parameter to limit the import to five counter samples.
PS C:\> Import-Counter -Path "Disk.blg" -MaxSamples 5

The second command uses array notation and the Windows PowerShell range operator (..) to get the last five counter samples from the file. These are the five newest samples.
PS C:\> (Import-Counter -Path Disk.blg)[-1 .. -5]

此範例示範如何從性能計數器記錄檔匯入五個最舊和最新的範例。

範例 7:從檔案取得計數器數據的摘要

PS C:\> Import-Counter "D:\Samples\Memory.blg" -Summary

OldestRecord            NewestRecord            SampleCount
------------            ------------            -----------
7/10/2008 2:59:18 PM    7/10/2008 3:00:27 PM    1000

此命令會使用 Import-Counter Cmdlet Summary 參數來取得 Memory.blg 檔案中計數器數據的摘要。

範例 8:更新性能計數器記錄檔

The first command uses the *ListSet* parameter of **Import-Counter** to get the counters in OldData.blg, an existing counter log file. The command uses a pipeline operator (|) to send the data to a ForEach-Object command that gets only the values of the **PathsWithInstances** property of each object
PS C:\> $Counters = Import-Counter OldData.blg -ListSet * | ForEach-Object {$_.PathsWithInstances}

The second command gets updated data for the counters in the $Counters variable. It uses the Get-Counter cmdlet to get a current sample, and then export the results to the NewData.blg file.
PS C:\> Get-Counter -Counter $Counters -MaxSamples 20 | Export-Counter C:\Logs\NewData.blg

此範例會更新性能計數器記錄檔。

範例 9:從多個檔案匯入效能記錄數據,然後儲存

PS C:\> $Counters = "D:\test\pdata.blg", "D:\samples\netlog.blg" | Import-Counter

此命令會從兩個記錄匯入效能記錄數據,並將數據儲存在 $Counters 變數中。 此命令會使用管線運算符將效能記錄路徑傳送至 Import-Counter,以從指定的路徑匯入數據。

請注意,每個路徑都以引號括住,而且路徑會以逗號彼此分隔。

參數

-Counter

指定性能計數器,做為字串數位。 根據預設,Import-Counter 會從輸入檔中的所有計數器匯入所有數據。 輸入一或多個計數器路徑。 路徑的實例部分允許通配符。

每個計數器路徑都有下列格式。 路徑中需要 ComputerName 值。 例如:

  • \\<ComputerName>\<CounterSet>(<Instance>)\<CounterName>

例如:

  • \\Server01\Processor(2)\% User Time
  • \\Server01\Processor(*)\% Processor Time

參數屬性

類型:

String[]

預設值:All counter
支援萬用字元:True
不要顯示:False

參數集

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

-EndTime

指定此 Cmdlet 匯入 startTime 和此參數時間戳之間的計數器數據結束日期和時間。 輸入 DateTime 物件,例如 Get-Date Cmdlet 所建立的物件。 根據預設,Import-Counter 會匯入 Path 參數所指定檔案中的所有計數器數據。

參數屬性

類型:DateTime
預設值:No end time
支援萬用字元:False
不要顯示:False

參數集

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

-ListSet

指定匯出檔案中所表示的性能計數器集合。 具有此參數的命令不會匯入任何數據。

輸入一或多個計數器集名稱。 允許使用通配符。 若要取得檔案中的所有計數器集合,請輸入 Import-Counter -ListSet *

參數屬性

類型:

String[]

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

參數集

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

-MaxSamples

指定要匯入之每個計數器的樣本數目上限。 根據預設,Get-Counter 會匯入 Path 參數所指定檔案中的所有數據。

參數屬性

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

參數集

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

-Path

指定要匯入之檔案的檔案路徑。 這是必要參數。

輸入您使用 Export-Counter Cmdlet 導出之 .csv,, . tsv 或 .blg 檔案的路徑和檔名。 您只能指定一個 .csv 或 .tsv 檔案,但您可以在每個命令中指定多個 .blg 檔案(最多 32 個)。 您也可以使用管線將檔案路徑字串(以引號括住)傳送至 Import-Counter

參數屬性

類型:

String[]

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

參數集

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

-StartTime

指定此 Cmdlet 取得計數器資料的開始日期和時間。 輸入 DateTime 物件,例如由 Get-Date Cmdlet 所建立的物件。 根據預設,Import-Counter 會匯入 Path 參數所指定檔案中的所有計數器數據。

參數屬性

類型:DateTime
預設值:No start time
支援萬用字元:False
不要顯示:False

參數集

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

-Summary

指出此 Cmdlet 會取得匯入數據的摘要,而不是取得個別的計數器數據範例。

參數屬性

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

參數集

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

CommonParameters

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

輸入

String

您可以使用管線將性能計數器記錄路徑傳送至此 Cmdlet。

輸出

Microsoft.PowerShell.Commands.GetCounter.PerformanceCounterSampleSet, Microsoft.PowerShell.Commands.GetCounter.CounterSet, Microsoft.PowerShell.Commands.GetCounter.CounterFileInfo

此 Cmdlet 會傳回 Microsoft.PowerShell.Commands.GetCounter.PerformanceCounterSampleSet。 如果您使用 ListSet 參數,此 Cmdlet 會傳回 Microsoft.PowerShell.Commands.GetCounter.CounterSet 物件。 如果您使用 Summary 參數,此 Cmdlet 會傳回 Microsoft.PowerShell.Commands.GetCounter.CounterFileInfo 物件。

備註

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