powershellscripts.com

Tutorials  PowerShell Cmdlet Help for Export-Alias



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 file. If the output file does not exist, t
he 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 that 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 existing 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 na
me 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 comment 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 the file.

By default, Export-Alias overwrites files without warning, unless the read-only or hidden attribute is set or t
he NoClobber parameter is used in the command. The NoClobber parameter takes precedence over the Force paramete
r when both are used in a command.

The Force parameter cannot force Export-Alias to overwrite files with the 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 parameter is used in the command.

If the NoClobber parameter is omitted, Export-Alias will overwrite an existing file without warning, unless the
read-only attribute is set on the file. NoClobber takes precedence over the Force parameter, which permits Exp
ort-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 default, this cmdlet does not generate any ou
tput.

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 parameter 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 to the current scope (0 through the numbe
r of scopes where 0 is the current scope and 1 is its parent). "Local" is the default. For more information, se
e 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 actually 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.Management.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 file.

Because the NoClobber parameter is specified, the command will fail if an Alias.csv file already exists in the curr
ent 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 file.

The command uses the Description parameter to add a description to the comments at the top of the file.

The command also uses the Force parameter to overwrite any existing Alias.csv files, even if they have the read-onl
y 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 generates.

The first command exports the aliases in the session to the Alias.ps1 file. It uses the As parameter with a value o
f Script to generate a file that contains a Set-Alias command for each alias.

The second command adds the aliases in the Alias.ps1 file to the CurrentUser-CurrentHost profile. (The path to the
profile is saved in the $profile variable.) The command uses the Get-Content cmdlet to get the aliases from the Ali
as.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 remote session on the Server01 computer.
The third command uses the New-PSSession cmdlet to create the session. The fourth command uses the FilePath paramet
er of the Invoke-Command cmdlet to run the Alias.ps1 file in the new session.






RELATED LINKS
Online version: http://go.microsoft.com/fwlink/?LinkID=113296
Import-Alias
Get-Alias
New-Alias
Set-Alias