Export-Counter
将性能计数器数据导出到日志文件。
语法
Export-Counter
[-Path] <String>
[-FileFormat <String>]
[-MaxSize <UInt32>]
-InputObject <PerformanceCounterSampleSet[]>
[-Force]
[-Circular]
[<CommonParameters>]
说明
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 |
Position: | Named |
默认值: | False |
必需: | False |
接受管道输入: | False |
接受通配符: | False |
-FileFormat
指定输出日志文件的输出格式。
此参数的可接受值为:
- CSV
- TSV
- BLG
默认值为 BLG。
类型: | String |
Position: | Named |
默认值: | BLG |
必需: | False |
接受管道输入: | False |
接受通配符: | False |
-Force
如果现有文件存在于 Path 参数指定的位置,则覆盖并替换现有文件。
类型: | SwitchParameter |
Position: | Named |
默认值: | False |
必需: | False |
接受管道输入: | False |
接受通配符: | False |
-InputObject
指定要导出的计数器数据,作为数组。 输入包含数据或获取数据的命令的变量,例如 Get-Counter 或 Import-Counter cmdlet。
类型: | PerformanceCounterSampleSet[] |
Position: | Named |
默认值: | None |
必需: | True |
接受管道输入: | True |
接受通配符: | False |
-MaxSize
指定输出文件的最大大小。
如果指定了 循环 参数,则当日志文件达到指定的最大大小时,将删除最早的条目,因为添加较新的条目。 如果未指定 循环 参数,则当日志文件达到指定的最大大小时,不会添加新数据,cmdlet 将生成非终止错误。
类型: | UInt32 |
Position: | Named |
默认值: | None |
必需: | False |
接受管道输入: | False |
接受通配符: | False |
-Path
指定输出文件的路径和文件名。 在本地计算机上输入相对或绝对路径,或远程计算机的统一命名约定 (UNC) 路径,例如 \\Computer\Share\file.blg。 此参数是必需的。
文件格式由 FileFormat 参数的值确定,而不是路径中的文件扩展名。
类型: | String |
别名: | PSPath |
Position: | 0 |
默认值: | None |
必需: | True |
接受管道输入: | True |
接受通配符: | False |
输入
可以通过管道将性能计数器数据从 Get-Counter 或 Import-Counter 传递给此 cmdlet。
输出
None
备注
日志文件生成器要求所有输入对象具有相同的计数器路径,并且这些对象按升序排列。
第一个输入对象的计数器类型和路径确定日志文件中记录的属性。 如果其他输入对象没有记录属性的值,则属性字段为空。 如果对象具有未记录的属性值,则忽略额外的属性值。
性能监视器可能无法读取 导出计数器 生成的所有日志。 例如,性能监视器要求所有对象具有相同的路径,并且所有对象都以相同的时间间隔分隔。
Import-Counter cmdlet 没有 ComputerName 参数。 但是,如果计算机配置为远程 Windows PowerShell Windows PowerShell,则可以使用 Invoke-Command cmdlet 在远程计算机上运行 Import-Counter 命令。