Export PerformanceCounterSampleSet objects to log files. Export-Counter is designed to export data that is returned by Get-Counter and Import-Counter.

      Export-Counter [-Path] string -InputObject PerformanceCounterSampleSet[]
         [-Circular] [-FileFormat string] [-Force] [-MaxSize int] [CommonParameters]

       Indicates that output file should be a circular log with first in, first
       out (FIFO) format. When you include this parameter, the -MaxSize parameter is required.

       The output format of the output log file.
       Valid values are CSV, TSV, and BLG.  The default value is BLG.

       Overwrite and replace an existing file if one exists in the location specified by -Path.

   -InputObject PerformanceCounterSampleSet[]
       The counter data to export.
       Enter a variable that contains the data or a command that gets the data, 
       such as a Get-Counter or Import-Counter command.

   -MaxSize int
       The maximum size of the output file. 
       If the Circular parameter is specified, then when the log file reaches the
       specified maximum size, the oldest entries are deleted as newer ones are added.
       If the Circular parameter is not specified, then when the log file 
       reaches the specified maximum size, no new data is added and the cmdlet
       generates a non-terminating error.

   -Path string
       The path and file name of the output file.
       Enter a relative or absolute path on the local computer, or a UNC path to a remote computer,
       such as \\Computer\Share\file.blg. This parameter is required. 

       Note: The file format is determined by the value of -FileFormat, not by the file name extension.

If you type only a filename as the Path, PowerShell will create a (.psc1) file in the current directory.

If Export-Console is run repeatedly in the same session, then -Path may be omitted, in this case Export-Console will overwrite the last console file written to.


Use Get-Counter to collect processor time data and pipe this to Export-Counter creating the file myproc.blg:

PS C:> Get-Counter "\Processor(*)\% Processor Time" -max 50 |
Export-Counter -path $home\myproc.blg

Import performance counter data from myperf.csv (previously exported by Export-Counter) the pipe the imported data to Export-Counter and create a circular log that wraps at 2 GB.

PS C:> Import-Counter myperf.csv |
Export-Counter -path threadtest.blg -circular -maxsize 2GB

Collect working set counter data from Server64, a remote computer and save the data in the $pws variable:

PS C:> $pws = Get-Counter -computername Server64 -counter "\Process(*)\Working Set - Private" -maxSamples 20

Now pipe the data in $pws to Export-Counter, which saves it to ss64.blg:

PS C:> $pws | Export-Counter -path \\Server64\Perf\ss64.blg

Filter and re-log existing performance data, DiskSpace.blg contains "LogicalDisk\% Free Space" counter data for hundreds of remote computers in the enterprise. The $lowSpace variable is then set to objects with CookedValues of less than 15 (percent), this data is then exported to LowDiskSpace.blg:

PS C:> $all = Import-Counter DiskSpace.blg
PS C:> $lowSpace = $all.countersamples | where {$_.cookedvalues -lt 15}
PS C:> $lowSpace | Export-Counter -path LowDiskSpace.blg

“Love all. Trust a few. Do wrong to none” ~ William Shakespeare

Related PowerShell Cmdlets

Get-Counter - Get performance counter data.
Import-Counter - Import performance counter log files.

Copyright © 1999-2024 SS64.com
Some rights reserved