Export-Counter
パフォーマンス カウンター データをログ ファイルにエクスポートします。
構文
Export-Counter
[-Path] <String>
[-FileFormat <String>]
[-MaxSize <UInt32>]
-InputObject <PerformanceCounterSampleSet[]>
[-Force]
[-Circular]
[<CommonParameters>]
説明
Export-Counter コマンドレットは、パフォーマンス カウンター データ (PerformanceCounterSampleSet オブジェクト) をバイナリ パフォーマンス ログ (.blg)、コンマ区切り値 (.csv)、またはタブ区切り値 (.tsv) 形式でログ ファイルにエクスポートします。 このコマンドレットを使用して、パフォーマンス カウンター データをログに記録できます。
Export-Counter コマンドレットは、Get-Counter コマンドレットと Import-Counter コマンドレットによって返されるデータをエクスポートするように設計されています。
このコマンドレットは、Windows 7、Windows Server 2008 R2、およびそれ以降のバージョンの Windows でのみ実行されます。
例
例 1: カウンター データをファイルにエクスポートする
PS C:\> Get-Counter "\Processor(*)\% Processor Time" | Export-Counter -Path $home\Counters.blg
このコマンドは、カウンタデータをBLGファイルにエクスポートします。
このコマンドでは、Get-Counter コマンドレットを使用してプロセッサ時間データを収集します。 パイプライン演算子 (|) を使用して、データを Export-Counter コマンドレットに送信します。 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 コマンドレットを使用して既存のデータを再ログする方法を示します。
パラメーター
-Circular
出力ファイルが、先入れ先出し (FIFO) 形式の循環ログであることを示します。 このパラメーターを含める場合は、maxSize パラメーター が必要です。
型: | SwitchParameter |
配置: | Named |
規定値: | False |
必須: | False |
パイプライン入力を受け取る: | False |
ワイルドカード文字を受け取る: | False |
-FileFormat
出力ログ ファイルの出力形式を指定します。
このパラメーターに使用できる値は次のとおりです。
- CSV
- TSV
- BLGの
デフォルト値は BLG です。
型: | String |
配置: | Named |
規定値: | BLG |
必須: | False |
パイプライン入力を受け取る: | False |
ワイルドカード文字を受け取る: | False |
-Force
Path パラメーターで指定された場所に既存のファイルが存在する場合、既存のファイルを上書きして置き換えます。
型: | SwitchParameter |
配置: | Named |
規定値: | False |
必須: | False |
パイプライン入力を受け取る: | False |
ワイルドカード文字を受け取る: | False |
-InputObject
配列として、エクスポートするカウンター データを指定します。 データを含む変数、またはデータを取得するコマンド ( Get-Counter や Import-Counter コマンドレットなど) を入力します。
型: | PerformanceCounterSampleSet[] |
配置: | Named |
規定値: | None |
必須: | True |
パイプライン入力を受け取る: | True |
ワイルドカード文字を受け取る: | False |
-MaxSize
出力ファイルの最大サイズを指定します。
Circular パラメーターを指定した場合、ログ ファイルが指定した最大サイズに達すると、新しいエントリが追加されると、最も古いエントリが削除されます。 Circular パラメーターが指定されていない場合、ログ ファイルが指定された最大サイズに達すると、新しいデータは追加されず、コマンドレットによって終了しないエラーが生成されます。
型: | UInt32 |
配置: | Named |
規定値: | None |
必須: | False |
パイプライン入力を受け取る: | False |
ワイルドカード文字を受け取る: | False |
-Path
出力ファイルのパスとファイル名を指定します。 ローカル コンピューター上の相対パスまたは絶対パス、またはリモート コンピューターへの統一名前付け規則 (UNC) パス (\\Computer\Share\file.blg など) を入力します。 このパラメーターは必須です。
ファイル形式は、パス内のファイル名拡張子ではなく、FileFormat パラメーターの値によって決まります。
型: | String |
Aliases: | PSPath |
配置: | 0 |
規定値: | None |
必須: | True |
パイプライン入力を受け取る: | True |
ワイルドカード文字を受け取る: | False |
入力
パフォーマンス カウンター データは 、Get-Counter または Import-Counter からこのコマンドレットにパイプできます。
出力
None
メモ
ログ ファイル ジェネレーターは、すべての入力オブジェクトが同じカウンター パスを持ち、オブジェクトが昇順で配置されることを想定しています。
最初の入力オブジェクトのカウンターの種類とパスによって、ログ ファイルに記録されるプロパティが決まります。 他の入力オブジェクトに記録されたプロパティの値がない場合、プロパティ フィールドは空です。 オブジェクトに記録されなかったプロパティ値がある場合、追加のプロパティ値は無視されます。
パフォーマンス モニターは、 Export-Counter が生成するすべてのログを読み取れない場合があります。 たとえば、パフォーマンス モニターでは、すべてのオブジェクトが同じパスを持ち、すべてのオブジェクトが同じ時間間隔で区切られている必要があります。
Import-Counter コマンドレットには ComputerName パラメーターがありません。 ただし、コンピューターがリモート Windows PowerShell Windows PowerShell 用に構成されている場合は、Invoke-Command コマンドレットを使用して、リモート コンピューターで Import-Counter コマンドを実行できます。