powershellscripts.com

Tutorials  PowerShell Cmdlet Help for Export-Counter



NAME
Export-Counter

SYNOPSIS
The Export-Counter cmdlet takes PerformanceCounterSampleSet objects and exports them as counter log files.

SYNTAX
Export-Counter [-Path] -InputObject [-Circular ] [-FileFormat ing>] [-Force ] [-MaxSize ] []


DESCRIPTION
The Export-Counter cmdlet exports performance counter data (PerformanceCounterSampleSet objects) to log files in bi
nary performance log (.blg), comma-separated value (.csv), or tab-separated value (.tsv) format. You can use this
cmdlet to log or relog performance counter data.

Export-Counter is designed to export data that is returned by the Get-Counter and Import-Counter cmdlets.

Note: Export-Counter runs only on Windows 7, Windows Server 2008 R2, and later versions of Windows.


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

Required? false
Position? named
Default value
Accept pipeline input? false
Accept wildcard characters? false

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

Required? false
Position? named
Default value BLG
Accept pipeline input? false
Accept wildcard characters? false

-Force
Overwrites and replaces an existing file if one exists in the location specified by the Path parameter.

Required? false
Position? named
Default value
Accept pipeline input? false
Accept wildcard characters? false

-InputObject
Specifies 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.

Required? true
Position? named
Default value
Accept pipeline input? true (ByValue)
Accept wildcard characters? false

-MaxSize
Specifies 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 e
ntries 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.

Required? false
Position? named
Default value
Accept pipeline input? false
Accept wildcard characters? false

-Path
Specifies the path and file name of the output file. Enter a relative or absolute path on the local computer, o
r a Uniform Naming Convention (UNC) path to a remote computer, such as \\Computer\Share\file.blg. This paramete
r is required.

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

Required? true
Position? 2
Default value
Accept pipeline input? false
Accept wildcard characters? false


This cmdlet supports the common parameters: Verbose, Debug,
ErrorAction, ErrorVariable, WarningAction, WarningVariable,
OutBuffer and OutVariable. For more information, type,
"get-help about_commonparameters".

INPUTS
Microsoft.PowerShell.Commands.GetCounter.PerformanceCounterSampleSet
You can pipe performance counter data from Get-Counter or Import-Counter to Export-Counter.


OUTPUTS
None



NOTES


The log file generator expects that all input objects have the same counter path and that the objects are arran
ged in ascending time order.

The counter type and path of the first input object determines the properties recorded in the log file. If othe
r input objects do not have a value for a recorded property, the property field is empty. If the objects have p
roperty values that were not recorded, the extra property values are ignored.

Performance Monitor might not be able to read all logs that Export-Counter generates. For example, Performance
Monitor requires that all objects have the same path and that all objects are separated by the same time interv
al.

The Import-Counter cmdlet does not have a ComputerName parameter. However, if the computer is configured for Wi
ndows PowerShell remoting, you can use the Invoke-Command cmdlet to run an Import-Counter command on a remote c
omputer.


-------------------------- EXAMPLE 1 --------------------------

C:\PS># Export-Counter


Description
-----------
This command exports counter data to a .blg file.

The command uses the Get-Counter cmdlet to collect processor time data. It uses a pipeline operator (|) to send the
data to the Export-Counter cmdlet. The Export-Counter command uses the Path variable to specify the output file.

C:\PS> get-counter "\Processor(*)\% Processor Time" -max 50 | export-counter -path $home\counters.blg

Because the data set might be very large, this command sends the data to Export-Counter through the pipeline. If th
e data were saved in a variable, the command might use a disproportionate amount of memory.





-------------------------- EXAMPLE 2 --------------------------

C:\PS># Export-Counter


Description
-----------
These commands convert a CSV file to a counter data BLG format.

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 Po
werShell returns the value in bytes.

C:\PS> $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 t
o specify the location of the output file. It uses the Circular and MaxSize parameters to direct Export-Counter to
create a circular log that wraps at 1 GB.

C:\PS> import-counter threads.csv | export-counter -path threadtest.blg -circular -maxsize $1GBinBytes





-------------------------- EXAMPLE 3 --------------------------

C:\PS># Export-Counter


Description
-----------
This example shows how to get performance counter data from a remote computer and save the data in a file on the re
mote computer.


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.

C:\PS> $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 on the Server01 computer.

C:\PS> $c | export-counter -path \\Server01\Perf\WorkingSet.blg





-------------------------- EXAMPLE 4 --------------------------

C:\PS># Export-Counter


Description
-----------
This example shows how to use the Import-Counter and Export-Counter cmdlets to relog existing data.

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 t
han 200 remote computers in the enterprise.

C:\PS> $all = import-counter DiskSpace.blg


The second command uses the CounterSamples property of the sample set object in $all and the Where-Object cmdlet (a
lias = "where") to select objects with CookedValues of less than 15 (percent). The command saves the results in the
$lowSpace variable.

C:\PS> $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 cmd
let. The command uses the path variable to indicate that the selected data should be logged in the LowDiskSpace.blg
file.

C:\PS> $lowSpace | export-counter -path LowDiskSpace.blg






RELATED LINKS
Online version: http://go.microsoft.com/fwlink/?LinkID=138337
Get-Counter
Import-Counter