Import-Counter
パフォーマンス カウンター ログ ファイルをインポートし、ログ内の各カウンター サンプルを表すオブジェクトを作成します。
構文
Import-Counter
[-Path] <String[]>
[-StartTime <DateTime>]
[-EndTime <DateTime>]
[-Counter <String[]>]
[-MaxSamples <Int64>]
[<CommonParameters>]
Import-Counter
[-Path] <String[]>
-ListSet <String[]>
[<CommonParameters>]
Import-Counter
[-Path] <String[]>
[-Summary]
[<CommonParameters>]
説明
Import-Counter コマンドレットは、パフォーマンス カウンター ログ ファイルからパフォーマンス カウンター データをインポートし、ファイル内のカウンター サンプルごとにオブジェクトを作成します。 作成される PerformanceCounterSampleSet オブジェクトは、パフォーマンス カウンター データを収集するときに Get-Counter が返すオブジェクトと同じです。
カンマ区切り値 (.csv)、タブ区切り値 ( .tsv)、およびバイナリ パフォーマンス ログ (.blg) パフォーマンス ログ ファイルからデータをインポートできます。 .blg ファイルを使用している場合は、各コマンドで最大 32 個のファイルをインポートできます。 Import-Counter のパラメーターを使用して、インポートするデータをフィルター処理できます。
この機能を使用すると、Get-Counter コマンドレットと Export-Counter コマンドレットと共に、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"
このコマンドは、ProcessorData.blg ファイルから "Processor(_total)\Interrupts/sec" カウンタ データのみを $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 ファイルにエクスポートする方法を示します。 最初の 4 つのコマンドは、ファイルからカウンター パスを取得し、それらを $Data という名前の変数に保存します。 最後の 2 つのコマンドは、選択したデータをインポートし、選択したデータのみをエクスポートします。
例 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]
この例では、パフォーマンス カウンター ログ ファイルから最も古い 5 つのサンプルと 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 コマンドレットの 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
このコマンドは、2 つのログからパフォーマンス・ログ・データをインポートし、$Counters 変数にデータを保存します。 このコマンドでは、パイプライン 演算子を使用して、パフォーマンス ログ パスを Import-Counter に送信します。このパスは、指定されたパスからデータをインポートします。
各パスは引用符で囲まれており、パスはコンマで区切られています。
パラメーター
-Counter
文字列配列としてパフォーマンス カウンターを指定します。 デフォルトでは、 Import-Counter は入力ファイル内のすべてのカウンターからすべてのデータをインポートします。 1 つ以上のカウンター パスを入力します。 パスのインスタンス部分ではワイルドカードを使用できます。
各カウンター パスの形式は次のとおりです。 パスには ComputerName 値が必要です。 たとえば、次のようになります。
\\<ComputerName>\<CounterSet>(<Instance>)\<CounterName>
例えば次が挙げられます。
\\Server01\Processor(2)\% User Time
\\Server01\Processor(*)\% Processor Time
型: | String[] |
配置: | Named |
規定値: | All counter |
必須: | False |
パイプライン入力を受け取る: | False |
ワイルドカード文字を受け取る: | True |
-EndTime
このコマンドレットが、StartTime とこのパラメータータイムスタンプの間でカウンター データをインポートする終了日時を指定します。 Get-Date コマンドレットによって作成されたオブジェクトなど、 DateTime オブジェクトを入力します。 既定では、 Import-Counter は Path パラメーターで指定されたファイル内のすべてのカウンター データをインポートします。
型: | DateTime |
配置: | Named |
規定値: | No end time |
必須: | False |
パイプライン入力を受け取る: | False |
ワイルドカード文字を受け取る: | False |
-ListSet
エクスポートされたファイルで表されるパフォーマンス カウンター セットを指定します。 このパラメーターを指定したコマンドでは、データはインポートされません。
1 つ以上のカウンター セット名を入力します。
ワイルドカードを使用できます。
ファイル内のすべてのカウンター セットを取得するには、「Import-Counter -ListSet *
」と入力します。
型: | String[] |
配置: | Named |
規定値: | None |
必須: | True |
パイプライン入力を受け取る: | False |
ワイルドカード文字を受け取る: | True |
-MaxSamples
インポートする各カウンターのサンプルの最大数を指定します。 既定では、 Get-Counter は Path パラメーターで指定されたファイル内のすべてのデータをインポートします。
型: | Int64 |
配置: | Named |
規定値: | No maximum |
必須: | False |
パイプライン入力を受け取る: | False |
ワイルドカード文字を受け取る: | False |
-Path
インポートするファイルのファイル パスを指定します。 このパラメーターは必須です。
Export-Counter コマンドレットを使用してエクスポートした a、.csv,, . tsv、または .blg ファイルのパスとファイル名を入力します。 指定できる .csv ファイルまたは .tsv ファイルは 1 つだけですが、各コマンドで複数の .blg ファイル (最大 32 個) を指定できます。 また、ファイルパス文字列 (引用符で囲む) を Import-Counter にパイプすることもできます。
型: | String[] |
Aliases: | PSPath |
配置: | 0 |
規定値: | None |
必須: | True |
パイプライン入力を受け取る: | True |
ワイルドカード文字を受け取る: | True |
-StartTime
このコマンドレットがカウンター データを取得する開始日時を指定します。 DateTime オブジェクト (Get-Date コマンドレットによって作成されたオブジェクトなど) を入力します。 既定では、 Import-Counter は Path パラメーターで指定されたファイル内のすべてのカウンター データをインポートします。
型: | DateTime |
配置: | Named |
規定値: | No start time |
必須: | False |
パイプライン入力を受け取る: | False |
ワイルドカード文字を受け取る: | False |
-Summary
このコマンドレットは、個々のカウンター データ サンプルを取得するのではなく、インポートされたデータの概要を取得することを示します。
型: | SwitchParameter |
配置: | Named |
規定値: | False |
必須: | False |
パイプライン入力を受け取る: | False |
ワイルドカード文字を受け取る: | False |
入力
パフォーマンス カウンター ログ パスをこのコマンドレットにパイプできます。
出力
Microsoft.PowerShell.Commands.GetCounter.PerformanceCounterSampleSet, Microsoft.PowerShell.Commands.GetCounter.CounterSet, Microsoft.PowerShell.Commands.GetCounter.CounterFileInfo
このコマンドレットは、Microsoft.PowerShell.Commands.GetCounter.PerformanceCounterSampleSet を返します。 ListSet パラメーターを使用すると、このコマンドレットは Microsoft.PowerShell.Commands.GetCounter.CounterSet オブジェクト を返します。 Summary パラメーターを使用すると、このコマンドレットは Microsoft.PowerShell.Commands.GetCounter.CounterFileInfo オブジェクト を返します。
メモ
- このコマンドレットには、ComputerName パラメーターがありません。 ただし、コンピューターが Windows PowerShell リモート処理用に構成されている場合は、Invoke-Command コマンドレットを使用して、リモート コンピューターで Import-Counter コマンドを実行できます。