Example
NAME
Export-Counter
SYNOPSIS
The Export-Counter cmdlet takes PerformanceCounterSampleSet objects and exp
orts them as counter log files.
SYNTAX
Export-Counter [-Path] -InputObject [-Circular ] [-FileFormat ] [-Force ] [-MaxSize <
int>] []
DESCRIPTION
The Export-Counter cmdlet exports performance counter data (PerformanceCoun
terSampleSet objects) to log files in binary 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-Count
er and Import-Counter cmdlets.
Note: Export-Counter runs only on Windows 7, Windows Server 2008 R2, and la
ter versions of Windows.
PARAMETERS
-Circular
Indicates that output file should be a circular log with first in, firs
t out (FIFO) format. When you include this parameter, the MaxSize param
eter 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 C
SV, 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 th
e 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 entries are deleted as newer one
s 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 t
he 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 o
r absolute path on the local computer, or a Uniform Naming Convention (
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 the FileFormat para
meter, 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-Counte
r to Export-Counter.
OUTPUTS
None
NOTES
The log file generator expects that all input objects have the same cou
nter path and that the objects are arranged in ascending time order.
The counter type and path of the first input object determines the prop
erties recorded in the log file. If other input objects do not have a v
alue for a recorded property, the property field is empty. If the objec
ts have property values that were not recorded, the extra property valu
es are ignored.
Performance Monitor might not be able to read all logs that Export-Coun
ter generates. For example, Performance Monitor requires that all objec
ts have the same path and that all objects are separated by the same ti
me interval.
The Import-Counter cmdlet does not have a ComputerName parameter. Howev
er, if the computer is configured for Windows PowerShell remoting, you
can use the Invoke-Command cmdlet to run an Import-Counter command on a
remote computer.
-------------------------- 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 fi
le.
C:\PS> get-counter "\Processor(*)\% Processor Time" -max 50 | export-counte
r -path $home\counters.blg
Because the data set might be very large, this command sends the data to Ex
port-Counter through the pipeline. If the data were saved in a variable, th
e 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 t
o 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, Windo
ws PowerShell returns the value in bytes.
C:\PS> $1GBinBytes = 1GB
The second command uses the Import-Counter cmdlet to import performance cou
nter data from the Threads.csv file. The example presumes that this file wa
s previously exported by using the Export-Counter cmdlet.
A pipeline operator (|) sends the imported data to the Export-Counter cmdle
t. The command uses the Path parameter to specify the location of the outpu
t file. It uses the Circular and MaxSize parameters to direct Export-Counte
r to create a circular log that wraps at 1 GB.
C:\PS> import-counter threads.csv | export-counter -path threadtest.blg -ci
rcular -maxsize $1GBinBytes
-------------------------- EXAMPLE 3 --------------------------
C:\PS># Export-Counter
Description
-----------
This example shows how to get performance counter data from a remote comput
er and save the data in a file on the remote computer.
The first command uses the Get-Counter cmdlet to collect working set counte
r data from Server01, a remote computer. The command saves the data in the
$c variable.
C:\PS> $c = get-counter -computername Server01 -counter "\Process(*)\Workin
g Set - Private" -maxSamples 20
The second command uses a pipeline operator (|) to send the data in $c to t
he 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 coun
ter 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 m
ore than 200 remote computers in the enterprise.
C:\PS> $all = import-counter DiskSpace.blg
The second command uses the CounterSamples property of the sample set objec
t in $all and the Where-Object cmdlet (alias = "where") to select objects w
ith CookedValues of less than 15 (percent). The command saves the results i
n 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 $low
Space variable to the Export-Counter cmdlet. The command uses the path vari
able to indicate that the selected data should be logged in the LowDiskSpac
e.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
NAME
Export-ModuleMember
SYNOPSIS
Specifies the module members that are exported.
SYNTAX
Export-ModuleMember [[-Function] ] [-Alias ] [-Cmdlet <
string[]>] [-Variable ] []
DESCRIPTION
The Export-ModuleMember cmdlet specifies the module members (such as cmdlet
s, functions, variables, and aliases) that are exported from a script modul
e (.psm1) file, or from a dynamic module created by using the New-Module cm
dlet. This cmdlet can be used only in a script module file or a dynamic mod
ule.
If a script module does not include an Export-ModuleMember command, the fun
ctions in the script module are exported, but the variables and aliases are
not. When a script module includes an Export-ModuleMember command, only th
e members specified in the Export-ModuleMember command are exported.
If a script module contains multiple Export-ModuleMember commands, only the
members listed in an Export-ModuleMember command are exported.
You can also use Export-ModuleMember to export members that the script modu
le imports from other modules.
PARAMETERS
-Alias
Specifies the aliases that are exported from the script module file. En
ter the alias names. Wildcards are permitted.
Required? false
Position? named
Default value None
Accept pipeline input? true (ByPropertyName)
Accept wildcard characters? true
-Cmdlet
Specifies the cmdlets that are exported from the script module file. En
ter the cmdlet names. Wildcards are permitted.
You cannot create cmdlets in a script module file, but you can import c
mdlets from a binary module into a script module and re-export them fro
m the script module.
Required? false
Position? named
Default value None
Accept pipeline input? true (ByPropertyName)
Accept wildcard characters? true
-Function
Specifies the functions that are exported from the script module file.
Enter the function names. Wildcards are permitted. You can also pipe fu
nction name strings to Export-ModuleMember.
Required? false
Position? 1
Default value None
Accept pipeline input? true (ByValue, ByPropertyName)
Accept wildcard characters? true
-Variable
Specifies the variables that are exported from the script module file.
Enter the variable names (without a dollar sign). Wildcards are permitt
ed.
Required? false
Position? named
Default value None
Accept pipeline input? true (ByPropertyName)
Accept wildcard characters? true
This cmdlet supports the common parameters: Verbose, Debug,
ErrorAction, ErrorVariable, WarningAction, WarningVariable,
OutBuffer and OutVariable. For more information, type,
"get-help about_commonparameters".
INPUTS
System.String
You can pipe function name strings to Export-ModuleMember.
OUTPUTS
None
This cmdlet does not generate any output.
NOTES
To exclude a member from the list of exported members, add an Export-Mo
duleMember command that lists all other members but omits the member th
at you want to exclude.
-------------------------- EXAMPLE 1 --------------------------
C:\PS>Export-ModuleMember -function * -alias *
Description
-----------
This command exports the aliases defined in the script module, along with t
he functions defined in the script module.
To export the aliases, which are not exported by default, you must also exp
licitly specify the functions. Otherwise, only the aliases will be exported
.
-------------------------- EXAMPLE 2 --------------------------
C:\PS>Export-ModuleMember -function Get-Test, New-Test, Start-Test -alias g
tt, ntt, stt
Description
-----------
This command exports three aliases and three functions defined in the scrip
t module.
You can use this command format to specify the names of module members.
-------------------------- EXAMPLE 3 --------------------------
C:\PS>Export-ModuleMember
Description
-----------
This command specifies that no members defined in the script module are exp
orted.
This command prevents the module members from being exported, but it does n
ot hide the members. Users can read and copy module members or use the call
operator (&) to invoke module members that are not exported.
-------------------------- EXAMPLE 4 --------------------------
C:\PS>Export-ModuleMember -variable increment
Description
-----------
This command exports only the $increment variable from the script module. N
o other members are exported.
If you want to export a variable, in addition to exporting the functions in
a module, the Export-ModuleMember command must include the names of all of
the functions and the name of the variable.
-------------------------- EXAMPLE 5 --------------------------
C:\PS># From TestModule.psm1
function new-test
{ }
export-modulemember -function new-test
function validate-test
{ }
function start-test
{ }
set-alias stt start-test
export-modulemember -function *-test -alias stt
Description
-----------
These commands show how multiple Export-ModuleMember commands are interpret
ed in a script module (.psm1) file.
These commands create three functions and one alias, and then they export t
wo of the functions and the alias.
Without the Export-ModuleMember commands, all three of the functions would
be exported, but the alias would not be exported. With the Export-ModuleMem
ber commands, only the Get-Test and Start-Test functions and the STT alias
are exported.
-------------------------- EXAMPLE 6 --------------------------
C:\PS>new-module -script {function SayHello {"Hello!"}; set-alias Hi SayHel
lo; Export-ModuleMember -alias Hi -function SayHello}
Description
-----------
This command shows how to use Export-ModuleMember in a dynamic module that
is created by using the New-Module cmdlet.
In this example, Export-ModuleMember is used to export both the "Hi" alias
and the "SayHello" function in the dynamic module.
-------------------------- EXAMPLE 7 --------------------------
C:\PS>function export
{
param (
[parameter(mandatory=$true)] [validateset("function","variable")] $
type,
[parameter(mandatory=$true)] $name,
[parameter(mandatory=$true)] $value
)
if ($type -eq "function")
{
Set-item "function:script:$name" $value
Export-ModuleMember $name
}
else
{
Set-Variable -scope Script $name $value
Export-ModuleMember -variable $name
}
}
export function New-Test
{
...
}
function helper
{
...
}
export variable interval 0
$interval = 2
Description
-----------
This example includes a function named Export that declares a function or c
reates a variable, and then writes an Export-ModuleMember command for the f
unction or variable. This lets you declare and export a function or variabl
e in a single command.
To use the Export function, include it in your script module. To export a f
unction, type "Export" before the Function keyword.
To export a variable, use the following format to declare the variable and
set its value:
export variable
The commands in the example show the correct format. In this example, only
the New-Test function and the $Interval variable are exported.
RELATED LINKS
Online version: http://go.microsoft.com/fwlink/?LinkID=141551
Import-Module
Get-Module
Remove-Module
about_Modules
NAME
Export-Console
SYNOPSIS
Exports the names of snap-ins in the current session to a console file.
SYNTAX
Export-Console [[-Path] ] [-Force] [-NoClobber] [-Confirm] [-WhatIf
] []
DESCRIPTION
The Export-Console cmdlet exports the names of the Windows PowerShell snap-
ins in the current session to a Windows PowerShell console file (.psc1). Yo
u can use this cmdlet to save the snap-ins for use in future sessions.
To add the snap-ins in the .psc1 console file to a session, start Windows P
owerShell (Powershell.exe) at the command line by using Cmd.exe or another
Windows PowerShell session, and then use the PSConsoleFile parameter of Pow
ershell.exe to specify the console file.
For more information about Windows PowerShell snap-ins, see about_PSSnapins
.
PARAMETERS
-Force []
Overwrites the data in a console file without warning, even if the file
has the read-only attribute. The read-only attribute is changed and is
not reset when the command completes.
Required? false
Position? named
Default value
Accept pipeline input? false
Accept wildcard characters? false
-NoClobber []
Will not overwrite (replace the contents of) an existing console file.
By default, if a file exists in the specified path, Export-Console over
writes the file without warning.
Required? false
Position? named
Default value
Accept pipeline input? false
Accept wildcard characters? false
-Path
Specifies a path and file name for the console file (*.psc1). Enter a p
ath (optional) and name. Wildcards are not permitted.
If you type only a file name, Export-Console creates a file with that n
ame and the ".psc1" file name extension in the current directory.
This parameter is required unless you have opened Windows PowerShell wi
th the PSConsoleFile parameter or exported a console file during the cu
rrent session. It is also required when you use the NoClobber parameter
to prevent the current console file from being overwritten.
If you omit this parameter, Export-Console overwrites (replaces the con
tent of) the console file that was used most recently in this session.
The path to the most recently used console file is stored in the value
of the $ConsoleFileName automatic variable. For more information, see a
bout_Automatic_Variables.
Required? false
Position? 1
Default value
Accept pipeline input? true (ByValue, ByPropertyName)
Accept wildcard characters? false
-Confirm []
Prompts you for confirmation before executing the command.
Required? false
Position? named
Default value
Accept pipeline input? false
Accept wildcard characters? false
-WhatIf []
Describes what would happen if you executed the command without actuall
y executing the command.
Required? false
Position? named
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
System.String
You can pipe a path string to Export-Console.
OUTPUTS
System.IO.FileInfo
Export-Console creates a file that contains the exported aliases.
NOTES
When a console file (.psc1) is used to start the session, the name of t
he console file is automatically stored in the $ConsoleFileName automat
ic variable. The value of $ConsoleFileName is updated when you use the
Path parameter of Export-Console to specify a new console file. When n
o console file is used, $ConsoleFileName has no value ($null).
To use a Windows PowerShell console file in a new session, use the foll
owing syntax to start Windows PowerShell:
"powershell.exe -PsConsoleFile .psc1".
You can also save Windows PowerShell snap-ins for future sessions by ad
ding an Add-PSSnapin command to your Windows PowerShell profile. For mo
re information, see about_Profiles.
-------------------------- EXAMPLE 1 --------------------------
C:\PS>export-console -path $pshome\Consoles\ConsoleS1.psc1
Description
-----------
This command exports the names of Windows PowerShell snap-ins in the curren
t session to the ConsoleS1.psc1 file in the Consoles subdirectory of the Wi
ndows PowerShell installation directory, $pshome.
-------------------------- EXAMPLE 2 --------------------------
C:\PS>export-console
Description
-----------
This command exports the names of Windows PowerShell snap-ins from current
session to the Windows PowerShell console file that was most recently used
in the current session. It overwrites the previous file contents.
If you have not exported a console file during the current session, you are
prompted for permission to continue and then prompted for a file name.
-------------------------- EXAMPLE 3 --------------------------
C:\PS>add-pssnapin NewPSSnapin
C:\PS> export-console -path NewPSSnapinConsole.psc1
C:\PS> powershell.exe -PsConsoleFile NewPsSnapinConsole.psc1
Description
-----------
These commands add the NewPSSnapin Windows PowerShell snap-in to the curren
t session, export the names of Windows PowerShell snap-ins in the current s
ession to a console file, and then start a Windows PowerShell session with
the console file.
The first command uses the Add-PSSnapin cmdlet to add the NewPSSnapin snap-
in to the current session. You can only add Windows PowerShell snap-ins tha
t are registered on your system.
The second command exports the Windows PowerShell snap-in names to the NewP
SSnapinConsole.psc1 file.
The third command starts Windows PowerShell with the NewPSSnapinConsole.psc
1 file. Because the console file includes the Windows PowerShell snap-in na
me, the cmdlets and providers in the snap-in are available in the current s
ession.
-------------------------- EXAMPLE 4 --------------------------
C:\PS>export-console -path Console01
C:\PS> notepad console01.psc1
2.0
Description
-----------
This command exports the names of the Windows PowerShell snap-ins in the cu
rrent session to the Console01.psc1 file in the current directory.
The second command displays the contents of the Console01.psc1 file in Note
pad.
-------------------------- EXAMPLE 5 --------------------------
C:\PS>powershell.exe -PSConsoleFile Console01.psc1
C:\PS> add-pssnapin MySnapin
C:\PS> export-console NewConsole.psc1
C:\PS> $consolefilename
C:\PS> add-pssnapin SnapIn03
C:\PS> export-console
Description
-----------
This example shows how to use the $ConsoleFileName automatic variable to de
termine the console file that will be updated if you use Export-Console wit
hout a Path parameter value.
The first command uses the PSConsoleFile parameter of PowerShell.exe to ope
n Windows PowerShell with the Console01.psc1 file.
The second command uses the Add-PSSnapin cmdlet to add the MySnapin Windows
PowerShell snap-in to the current session.
The third command uses the Export-Console cmdlet to export the names of all
the Windows PowerShell snap-ins in the session to the NewConsole.psc1 file
.
The fourth command uses the $ConsoleFileName parameter to display the most
recently used console file. The sample output shows that NewConsole.ps1 is
the most recently used file.
The fifth command adds SnapIn03 to the current console.
The sixth command uses the ExportConsole cmdlet without a Path parameter. T
his command exports the names of all the Windows PowerShell snap-ins in the
current session to the most recently used file, NewConsole.psc1.
RELATED LINKS
Online version: http://go.microsoft.com/fwlink/?LinkID=113298
Add-PSSnapin
Get-PSSnapin
Remove-PSSnapin
NAME
Export-FormatData
SYNOPSIS
Saves formatting data from the current session in a formatting file.
SYNTAX
Export-FormatData [-Force] [-IncludeScriptBlock] [-InputObject ] [-NoClobber] [-Path ] []
DESCRIPTION
The Export-FormatData cmdlet creates Windows PowerShell formatting files (f
ormat.ps1xml) from the formatting objects in the current session. It takes
the ExtendedTypeDefinition objects that Get-FormatData returns and saves th
em in a file in XML format.
Windows PowerShell uses the data in formatting files (format.ps1xml) to gen
erate the default display of Microsoft .NET Framework objects in the sessio
n. You can view and edit the formatting files and use the Update-FormatData
cmdlet to add the formatting data to a session.
For more information about formatting files in Windows PowerShell, see abou
t_Format.ps1xml.
PARAMETERS
-Force []
Overwrites an existing output file, even if the file has the read-only
attribute.
Required? false
Position? named
Default value False
Accept pipeline input? false
Accept wildcard characters? false
-IncludeScriptBlock []
Determines whether script blocks in the format data are exported.
Because script blocks contain code and can be used maliciously, they ar
e not exported by default.
Required? false
Position? named
Default value False
Accept pipeline input? false
Accept wildcard characters? false
-InputObject
Specifies the format data objects to be exported. Enter a variable that
contains the objects or a command that gets the objects, such as a Get
-FormatData command. You can also pipe the objects from Get-FormatData
to Export-FormatData.
Required? false
Position? named
Default value
Accept pipeline input? true (ByValue)
Accept wildcard characters? false
-NoClobber []
Prevents the cmdlet from overwriting existing files. By default, Export
-FormatData overwrites files without warning unless the file has the re
ad-only attribute.
To direct Export-FormatData to overwrite read-only files, use the Force
parameter.
Required? false
Position? named
Default value
Accept pipeline input? false
Accept wildcard characters? false
-Path
Specifies a location for the output file. Enter a path (optional) and
file name with a format.ps1xml file name extension. If you omit the pat
h, Export-FormatData creates the file in the current directory.
If you use a file name extension other than .ps1xml, the Update-FormatD
ata cmdlet will not recognize the file.
If you specify an existing file, Export-FormatData overwrites the file
without warning, unless the file has the read-only attribute. To overwr
ite a read-only file, use the Force parameter. To prevent files from be
ing overwritten, use the NoClobber parameter.
Required? false
Position? named
Default value None
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
System.Management.Automation.ExtendedTypeDefinition
You can pipe ExtendedTypeDefinition objects from Get-FormatData to Expo
rt-FormatData.
OUTPUTS
None
Export-FormatData does not return any objects. It generates a file and
saves it in the specified path.
NOTES
To use any formatting file, including an exported formatting file, the
execution policy for the session must allow scripts and configuration f
iles to run. For more information, see about_Execution_Policies.
-------------------------- EXAMPLE 1 --------------------------
C:\PS>get-formatdata -typename * | export-formatdata -path allformat.ps1xml
-IncludeScriptBlock
Description
-----------
This command exports all of the format data in the session to the AllFormat
.ps1xml file.
The command uses the Get-FormatData cmdlet to get the format data in the se
ssion. A value of * (all) for the TypeName parameter directs the cmdlet to
get all of the data in the session.
The command uses a pipeline operator (|) to send the format data from the G
et-FormatData command to the Export-FormatData cmdlet, which exports the fo
rmat data to the AllFormat.ps1 file.
The Export-FormatData command uses the IncludeScriptBlock parameter to incl
ude script blocks in the format data in the file.
-------------------------- EXAMPLE 2 --------------------------
C:\PS>$f = get-formatdata -typename helpinfoshort
C:\PS> export-formatdata -inputObject $f -path c:\test\help.format.ps1xml -
IncludeScriptBlock
Description
-----------
These commands export the format data for the HelpInfoShort type to the Hel
p.format.ps1xml file.
The first command uses the Get-FormatData cmdlet to get the format data for
the HelpInfoShort type, and it saves it in the $f variable.
The second command uses the InputObject parameter of the Export-FormatData
to enter the format data saved in the $f variable. It also uses the Include
ScriptBlock parameter to include script blocks in the output.
-------------------------- EXAMPLE 3 --------------------------
C:\PS>get-formatdata -typename System.Diagnostics.Process | export-FormatDa
ta -path process.format.ps1xml
C:\PS> Update-FormatData -prependPath .\process.format.ps1xml
C:\PS> get-process p*
Handles NPM(K) PM(K) WS(K) VM(M) CPU(s) Id ProcessName
------- ------ ----- ----- ----- ------ -- -----------
323 5600 powershell
336 3900 powershell_ise
138 4076 PresentationFontCache
Description
-----------
This example shows the effect of omitting the IncludeScriptBlock parameter
from an Export-FormatData command.
The first command uses the Get-FormatData cmdlet to get the format data for
the System.Diagnostics.Process object that the Get-Process cmdlet returns.
The command uses a pipeline operator (|) to send the formatting data to th
e Export-FormatData cmdlet, which exports it to the Process.format.ps1xml f
ile in the current directory.
In this case, the Export-FormatData command does not use the IncludeScriptB
lock parameter.
The second command uses the Update-FormatData cmdlet to add the Process.for
mat.ps1xml file to the current session. The command uses the PrependPath pa
rameter to ensure that the formatting data for process objects in the Proce
ss.format.ps1xml file is found before the standard formatting data for proc
ess objects.
The third command shows the effects of this change. The command uses the Ge
t-Process cmdlet to get processes that have names that begin with "P". The
output shows that property values that are calculated by using script block
s are missing from the display.
RELATED LINKS
Online version: http://go.microsoft.com/fwlink/?LinkID=144302
Get-FormatData
Update-FormatData
NAME
Export-CSV
SYNOPSIS
Converts Microsoft .NET Framework objects into a series of comma-separated
value (CSV) variable-length strings and saves the strings in a CSV file.
SYNTAX
Export-CSV [[-Delimiter] ] [-Path] -InputObject [
-Encoding ] [-Force] [-NoClobber] [-NoTypeInformation] [-Confirm] [
-WhatIf] []
Export-CSV [-UseCulture] [-Path] -InputObject [-Encodin
g ] [-Force] [-NoClobber] [-NoTypeInformation] [-Confirm] [-WhatIf]
[]
DESCRIPTION
The Export-CSV cmdlet creates a CSV variable-length file that represents th
e objects that you submit.
You can then use the Import-CSV cmdlet to re-create objects from the CSV st
rings in the files. The resulting objects are CSV versions of the original
objects that consist of string representations of the property values and n
o methods.
You can also use the ConvertTo-CSV and ConvertFrom-CSV cmdlets to convert .
NET Framework objects to CSV strings (and back). Export-CSV is the same as
ConvertTo-CSV, except that it saves the CSV strings in a file.
You can use the parameters of the Export-CSV cmdlet to specify a delimiter
other than a comma or to direct Export-CSV to use the default delimiter for
the current culture.
When you submit multiple objects to Export-CSV, Export-CSV organizes the fi
le based on the properties of the first object that you submit. If the rema
ining objects do not have one of the specified properties, the property val
ue of that object is null, as represented by two consecutive commas. If the
remaining objects have additional properties, those property values are no
t included in the file.
For more information, see Export-CSV, and see the Notes section.
PARAMETERS
-Delimiter
Specifies a delimiter to separate the property values. The default is a
comma (,). Enter a character, such as a colon (:). To specify a semico
lon (;), enclose it in quotation marks.
Required? false
Position? 2
Default value , (comma)
Accept pipeline input? false
Accept wildcard characters? false
-Encoding
Specifies the encoding for the exported CSV file. Valid values are Unic
ode, UTF7, UTF8, ASCII, UTF32, BigEndianUnicode, Default, and OEM. The
default is ASCII.
Required? false
Position? named
Default value ASCII
Accept pipeline input? false
Accept wildcard characters? false
-Force []
Overwrites the file specified in path without prompting.
Required? false
Position? named
Default value
Accept pipeline input? false
Accept wildcard characters? false
-InputObject
Specifies the objects to export as CSV strings. Enter a variable that c
ontains the objects or type a command or expression that gets the objec
ts. You can also pipe objects to Export-CSV.
Required? true
Position? named
Default value
Accept pipeline input? true (ByValue, ByPropertyName)
Accept wildcard characters? false
-NoClobber []
Do not overwrite (replace the contents) of an existing file. By default
, if a file exists in the specified path, Export-CSV overwrites the fil
e without warning.
Required? false
Position? named
Default value
Accept pipeline input? false
Accept wildcard characters? false
-NoTypeInformation []
Omits the type information from the CSV file. By default, the first lin
e of the CSV file contains "#TYPE " followed by the fully-qualified nam
e of the type of the .NET Framework object.
Required? false
Position? named
Default value
Accept pipeline input? false
Accept wildcard characters? false
-Path
Specifies the path to the CSV output file. The parameter is required.
Required? true
Position? 1
Default value
Accept pipeline input? false
Accept wildcard characters? false
-UseCulture []
Use the list separator for the current culture as the item delimiter. T
he default is a comma (,).
This parameter is very useful in scripts that are being distributed to
users worldwide. To find the list separator for a culture, use the foll
owing command: (Get-Culture).TextInfo.ListSeparator.
Required? false
Position? named
Default value Comma
Accept pipeline input? false
Accept wildcard characters? false
-Confirm []
Prompts you for confirmation before executing the command.
Required? false
Position? named
Default value
Accept pipeline input? false
Accept wildcard characters? false
-WhatIf []
Describes what would happen if you executed the command without actuall
y executing the command.
Required? false
Position? named
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
System.Management.Automation.PSObject
You can pipe any .NET Framework object to Export-CSV.
OUTPUTS
System.String
The CSV list is sent to the file designated in the Path parameter.
NOTES
The Export-CSV cmdlet converts the objects that you submit into a serie
s of CSV variable-length strings and saves them in the specified text f
ile. You can use Export-CSV to save objects in a CSV file and then use
the Import-CSV cmdlet to create objects from the text in the CSV file.
In the CSV file, each object is represented by a comma-separated list o
f the property values of the object. The property values are converted
to strings (by using the ToString() method of the object), so they are
generally represented by the name of the property value. Export-CSV doe
s not export the methods of the object.
The format of an exported file is as follows:
-- The first line of the CSV file contains the string '#TYPE ' followed
by the fully qualified name of the .NET Framework type of the object,
such as #TYPE System.Diagnostics.Process. To suppress this line, use th
e NoTypeInformation parameter.
-- The next line of the CSV file represents the column headers. It cont
ains a comma-separated list of the names of all the properties of the f
irst object.
-- Additional lines of the file consist of comma-separated lists of the
property values of each object.
-------------------------- EXAMPLE 1 --------------------------
C:\PS>get-process wmiprvse | select-object basePriority,ID,SessionID,Workin
gSet | export-csv -path data.csv
Description
-----------
This command selects a few properties of the wmiprvse process and exports t
hem to a CSV format file named data.csv.
-------------------------- EXAMPLE 2 --------------------------
C:\PS>get-process | export-csv processes.csv
C:\PS> get-process | export-csv processes.csv
# In processes.csv
#TYPE System.Diagnostics.Process
__NounName,Name,Handles,VM,WS,PM,NPM,Path,Company,CPU,FileVersion,...
Process,powershell,626,201666560,76058624,61943808,11960,C:\WINDOWS...
Process,powershell,257,151920640,38322176,37052416,7836,C:\WINDOWS\...
Description
-----------
This command exports objects representing the processes on the computer to
the Processes.csv file in the current directory. Because it does not specif
y a delimiter, a comma (,) is used to separate the fields in the file.
-------------------------- EXAMPLE 3 --------------------------
C:\PS>get-process | export-csv processes.csv -Delimiter ";"
# In processes.csv
#TYPE System.Diagnostics.Process
__NounName;Name;Handles;VM;WS;PM;NPM;Path;Company;CPU;FileVersion;...
Process;powershell;626;201666560;76058624;61943808;11960;C:\WINDOWS...
Process;powershell;257;151920640;38322176;37052416;7836;C:\WINDOWS\...
Description
-----------
This command exports objects representing the processes on the computer to
the Processes.csv file in the current directory. It uses the Delimiter para
meter to specify the semicolon (;). As a result, the fields in the file are
separated by semicolons.
-------------------------- EXAMPLE 4 --------------------------
C:\PS>get-process | export-csv processes.csv -UseCulture
Description
-----------
This command exports objects representing the processes on the computer to
the Processes.csv file in the current directory. It uses the UseCulture par
ameter to direct Export-CSV to use the delimiter specified by the ListSepar
ator property of the current culture.
-------------------------- EXAMPLE 5 --------------------------
C:\PS>get-process | export-csv processes.csv -NoTypeInformation
C:\PS> get-process | export-csv processes.csv -NoTypeInformation
# In processes.csv
__NounName,Name,Handles,VM,WS,PM,NPM,Path,Company,CPU,FileVersion,...
Process,powershell,626,201666560,76058624,61943808,11960,C:\WINDOWS...
Process,powershell,257,151920640,38322176,37052416,7836,C:\WINDOWS\...
Description
-----------
This command exports objects representing the processes on the computer to
the Processes.csv file in the current directory. It uses the NoTypeInformat
ion parameter to suppress the type information in the file.
RELATED LINKS
Online version: http://go.microsoft.com/fwlink/?LinkID=113299
Import-CSV
ConvertTo-CSV
ConvertFrom-CSV
NAME
Export-Alias
SYNOPSIS
Exports information about currently defined aliases to a file.
SYNTAX
Export-Alias [-Path] [[-Name] ] [-Append]
[-As {Csv | Script}] [-Description ] [-Force] [-NoClobber]
[-PassThru] [-Scope ] [-Confirm] [-WhatIf] []
DESCRIPTION
The Export-Alias cmdlet exports the aliases in the current session to a fil
e. If the output file does not exist, the cmdlet will create it.
Export-Alias can export the aliases in a particular scope or all scopes, it
can generate the data in CSV format or as a series of Set-Alias commands t
hat you can add to a session or to a Windows PowerShell profile.
PARAMETERS
-Append []
Appends the output to the specified file, rather than overwriting the e
xisting contents of that file.
Required? false
Position? named
Default value
Accept pipeline input? false
Accept wildcard characters? false
-As
Determines the output format. CSV is the default.
Valid values are:
-- CSV: Comma-separated value (CSV) format.
-- Script: Creates a Set-Alias command for each exported alias. If you
name the output file with a .ps1 file name extension, you can run it as
a script to add the aliases to any session.
Required? false
Position? named
Default value
Accept pipeline input? false
Accept wildcard characters? false
-Description
Adds a description to the exported file. The description appears as a c
omment at the top of the file, following the header information.
Required? false
Position? named
Default value
Accept pipeline input? false
Accept wildcard characters? false
-Force []
Overwrites the output file, even if the read-only attribute is set on t
he file.
By default, Export-Alias overwrites files without warning, unless the r
ead-only or hidden attribute is set or the NoClobber parameter is used
in the command. The NoClobber parameter takes precedence over the Force
parameter when both are used in a command.
The Force parameter cannot force Export-Alias to overwrite files with t
he hidden attribute.
Required? false
Position? named
Default value Does not overwrite read-only files.
Accept pipeline input? false
Accept wildcard characters? false
-Name
Specifies the names of the aliases to export. Wildcards are permitted.
By default, Export-Alias exports all aliases in the session or scope.
Required? false
Position? 2
Default value Export all aliases
Accept pipeline input? true (ByPropertyName)
Accept wildcard characters? false
-NoClobber []
Prevents Export-Alias from overwriting any files, even if the Force par
ameter is used in the command.
If the NoClobber parameter is omitted, Export-Alias will overwrite an e
xisting file without warning, unless the read-only attribute is set on
the file. NoClobber takes precedence over the Force parameter, which pe
rmits Export-Alias to overwrite a file with the read-only attribute.
NoClobber does not prevent the Append parameter from adding content to
an existing file.
Required? false
Position? named
Default value Overwrites read-write files.
Accept pipeline input? false
Accept wildcard characters? false
-PassThru []
Returns objects that represent the aliases that were exported. By defau
lt, this cmdlet does not generate any output.
Required? false
Position? named
Default value No output
Accept pipeline input? false
Accept wildcard characters? false
-Path
Specifies the path to the output file. Wildcards are permitted, but the
resulting path value must resolve to a single file name. This paramete
r is required.
Required? true
Position? 1
Default value None
Accept pipeline input? false
Accept wildcard characters? false
-Scope
Specifies the scope from which the aliases should be exported.
Valid values are "Global", "Local", or "Script", or a number relative t
o the current scope (0 through the number of scopes where 0 is the curr
ent scope and 1 is its parent). "Local" is the default. For more inform
ation, see about_Scopes.
Required? false
Position? named
Default value Local
Accept pipeline input? false
Accept wildcard characters? false
-Confirm []
Prompts you for confirmation before executing the command.
Required? false
Position? named
Default value
Accept pipeline input? false
Accept wildcard characters? false
-WhatIf []
Describes what would happen if you executed the command without actuall
y executing the command.
Required? false
Position? named
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
None.
You cannot pipe objects to this cmdlet.
OUTPUTS
None or System.Management.Automation.AliasInfo
When you use the Passthru parameter, Export-Alias returns a System.Mana
gement.Automation.AliasInfo object that represents the alias. Otherwise
, this cmdlet does not generate any output.
NOTES
You can only Export-Aliases to a file.
-------------------------- EXAMPLE 1 --------------------------
C:\PS>export-alias -path alias.csv
Description
-----------
This command exports current alias information to a file named Alias.csv in
the current directory.
-------------------------- EXAMPLE 2 --------------------------
C:\PS>export-alias -path alias.csv -noclobber
Description
-----------
This command exports the aliases in the current session to an Alias.csv fil
e.
Because the NoClobber parameter is specified, the command will fail if an A
lias.csv file already exists in the current directory.
-------------------------- EXAMPLE 3 --------------------------
C:\PS>export-alias -path alias.csv -append -description "Appended Aliases"
-force
Description
-----------
This command appends the aliases in the current session to the Alias.csv fi
le.
The command uses the Description parameter to add a description to the comm
ents at the top of the file.
The command also uses the Force parameter to overwrite any existing Alias.c
sv files, even if they have the read-only attribute.
-------------------------- EXAMPLE 4 --------------------------
C:\PS>export-alias -path alias.ps1 -as script
C:\PS> add-content -path $profile -value (get-content alias.ps1)
C:\PS> $s = new-pssession -computername Server01
C:\PS> invoke-command -session $s -filepath .\alias.ps1
Description
-----------
This example shows how to use the script file format that Export-Alias gene
rates.
The first command exports the aliases in the session to the Alias.ps1 file.
It uses the As parameter with a value of Script to generate a file that co
ntains a Set-Alias command for each alias.
The second command adds the aliases in the Alias.ps1 file to the CurrentUse
r-CurrentHost profile. (The path to the profile is saved in the $profile va
riable.) The command uses the Get-Content cmdlet to get the aliases from th
e Alias.ps1 file and the Add-Content cmdlet to add them to the profile. For
more information, see about_Profiles.
The third and fourth commands add the aliases in the Alias.ps1 file to a r
emote session on the Server01 computer. The third command uses the New-PSSe
ssion cmdlet to create the session. The fourth command uses the FilePath pa
rameter of the Invoke-Command cmdlet to run the Alias.ps1 file in the new s
ession.
RELATED LINKS
Online version: http://go.microsoft.com/fwlink/?LinkID=113296
Import-Alias
Get-Alias
New-Alias
Set-Alias
NAME
Export-PSSession
SYNOPSIS
Imports commands from another session and saves them in a Windows PowerShel
l module.
SYNTAX
Export-PSSession [-Session] [-OutputModule] [[-Command
Name] ] [[-FormatTypeName] ] [-AllowClobber] [-Argument
List