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 cmdlet 从性能计数器日志文件导入性能计数器数据,并为文件中的每个计数器示例创建对象。 PerformanceCounterSampleSet 创建的对象与 Get-Counter 收集性能计数器数据时返回的对象相同。

可以从逗号分隔值(.csv)、制表符分隔值(.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]

此示例演示如何从性能计数器日志文件导入 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 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[]
Position:Named
默认值:All counter
必需:False
接受管道输入:False
接受通配符:True

-EndTime

指定此 cmdlet 在 StartTime 和此参数时间戳之间导入计数器数据的结束日期和时间。 输入 DateTime 对象,例如由 Get-Date cmdlet 创建的对象。 默认情况下,Import-Counter 导入由 Path 参数指定的文件中的所有计数器数据。

类型:DateTime
Position:Named
默认值:No end time
必需:False
接受管道输入:False
接受通配符:False

-ListSet

指定导出文件中表示的性能计数器集。 具有此参数的命令不会导入任何数据。

输入一个或多个计数器集名称。 允许通配符。 若要获取文件中的所有计数器集,请键入 Import-Counter -ListSet *

类型:String[]
Position:Named
默认值:None
必需:True
接受管道输入:False
接受通配符:True

-MaxSamples

指定要导入的每个计数器的最大样本数。 默认情况下,Get-Counter 导入由 Path 参数指定的文件中的所有数据。

类型:Int64
Position:Named
默认值:No maximum
必需:False
接受管道输入:False
接受通配符:False

-Path

指定要导入的文件的文件路径。 此参数是必需的。

输入使用 Export-Counter cmdlet 导出的 .csv,, . tsv 或 .blg 文件的路径和文件名。 只能指定一个 .csv 或 .tsv 文件,但可以在每个命令中指定多个 .blg 文件(最多 32 个)。 还可以通过管道将文件路径字符串(以引号为单位)Import-Counter

类型:String[]
别名:PSPath
Position:0
默认值:None
必需:True
接受管道输入:True
接受通配符:True

-StartTime

指定此 cmdlet 获取计数器数据的开始日期和时间。 输入 DateTime 对象,例如由 Get-Date cmdlet 创建的对象。 默认情况下,Import-Counter 导入由 Path 参数指定的文件中的所有计数器数据。

类型:DateTime
Position:Named
默认值:No start time
必需:False
接受管道输入:False
接受通配符:False

-Summary

指示此 cmdlet 获取导入数据的摘要,而不是获取单个计数器数据示例。

类型:SwitchParameter
Position:Named
默认值:False
必需:False
接受管道输入:False
接受通配符:False

输入

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 命令。