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.

       -Verbose, -Debug, -ErrorAction, -ErrorVariable, -WarningAction, -WarningVariable,
       -OutBuffer -OutVariable.

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 Commands:

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

Copyright © SS64.com 1999-2018
Some rights reserved