Powershell alias

74 %
26 %
Information about Powershell alias
Technology

Published on February 24, 2014

Author: ltcrd

Source: slideshare.net

Powershell - Alias JASON

Cmdlet  (Get-Command –type Cmdlet).Length

Get-Command  The Get-Command cmdlet gets all commands that are installed on the computer, including cmdlets, aliases, functions, workflows, filters, scripts, and applications.  Example : Get-Command -CommandType Alias g*

Powershell Alias - Abbreviation  Get → g  Set → s  Item → i  Location → l  Command → cm  Get-Item → gi  Set-Item → si  Get-Location → gl  Get-Command → gcm

New-Alias  New-Alias [-Name] <string> [-Value] <string>  Example : New-Alias log Write-Host  Aliases created by using New-Alias are not saved after you exit the session or close Windows PowerShell  You can use the Export-Alias cmdlet to save your alias information to a file  You can later use Import-Alias to retrieve that saved alias information.

Get-Alias  The Get-Alias cmdlet gets the aliases in the current session.  This includes built-in aliases, aliases that you have set or imported, and aliases that you have added to your Windows PowerShell profile.  Example : Get-Alias l*  Example : if(Get-Alias log) { log “Alias Exists” }

Modify Alias  Example 1:   Example 2:   New-Alias log Write-Verbose –Force Set-Alias log Write-Verbose Example 3:    cd Alias: Set-Item log Write-Verbose Example 4:  cd Alias:  Set-Content log Write-Verbose

Getting to the Alias: Drive  This command changes the current location to the Alias: drive  To return to a file system drive, type the drive name. For example, type "set-location c:".  Example :  PS C:UsersJason> cd alias:  PS Alias:> dir l*

PowerShell Drive  We connect to PowerShell Providers by mounting the Providers PowerShell Drive(PSDrive)

Delete Alias  Use Remove-Item (del) cmlet  Example :  PS C:UsersJason> cd alias:  PS Alias:> del log  PS C:UsersJason> Remove-Item alias: log

Export-Alias  The Export-Alias cmdlet exports the aliases in the current session to a file.  Example 1: Export-Alias aliases.txt  Example 2 : Export-Alias aliases.txt log*  Example 3 : Export-Alias aliases.txt trace* -append  Example 4 : Export-Alias aliases.ps1 trace* -as Script

Export-Alias  Export-Alias aliases.txt

Export-Alias  Export-Alias aliases.ps1 -as Script

Import-Alias  The Import-Alias cmdlet imports an alias list from a file.  Beginning in Windows PowerShell 3.0, as a security feature, ImportAlias does not overwrite existing aliases by default.  To overwrite an existing alias, after assuring that the contents of the alias file is safe, use the Force parameter.  Example : Import-Alias aliases.txt

Q1  Get-ChildItem *.txt | Where-Object { $_.Length –gt 5KB } | ForEachObject { $_.Name }  Gci *.txt | ? { $_.Length –gt 5KB } | % { $_.Name }

Q2  是否可以建立一個為 「Get-Command」的別名??  Example:  New-Alias Get-Command dir

Reference  TechNet  http://technet.microsoft.com/en-us/library/ee176913.aspx

Add a comment

Related presentations

Related pages

Windows PowerShell 1.0 Aliases

The Windows PowerShell 1.0 Owner’s Manual has been retired. For the most up-to-date Windows PowerShell content, go to Using Windows PowerShell.
Read more

Get-Alias, Set-Alias: Kurznamen für PowerShell-Befehle ...

PowerShell bietet wie einige andere Kom­mando­inter­preter einen Alias-Mecha­nismus, der alternative Namen für Cmdlets oder Befehle definieren kann.
Read more

Using the New-Alias Cmdlet

Creating a New Windows PowerShell Alias. So you say that you like Windows PowerShell, but you have problems remembering some of the cmdlet names?
Read more

Using the Set-Alias Cmdlet

Just call Set-Alias followed by the alias name, followed by the appropriate cmdlet. That’s all you have to do. Although there’s no corresponding cmdlet ...
Read more

Powershell->Script-->Alias

Cuando invoques el script, debes asegurarte que se ejecuta en el mismo ámbito que la consola de Powershell, para que así se mantenga el alias definido ...
Read more

Set-Alias - PowerShell - ColorConsole, color the commands ...

PowerShell: Erstellt oder ändert einen Alias (alternativer Name) für ein Cmdlet oder anderes Befehlselement in der aktuellen Windows PowerShell-...
Read more

Windows PowerShell – Wikipedia

Windows PowerShell; Screenshot von PowerShell 5.0 unter Windows 8.1: Basisdaten; Entwickler: ... Windows PowerShell (Cmdlet) Windows PowerShell (Alias) cmd.exe
Read more

List of Aliases Used in PowerShell - I Love PowerShell

Here’s a list of aliases you can use for PowerShell. An alias is just a shortcut. You can use an alias from the console or in a script, and it works just ...
Read more

Set-Alias | PowerShell | SS64.com

Set-Alias. Create or change an alias. An alias is an alternate (usually shorter) name for a cmdlet, script, function, or executable file. Syntax Set-Alias ...
Read more

alias (command) - Wikipedia, the free encyclopedia

In computing, alias is a command in various command line interpreters such as Unix shells, 4DOS/4NT and Windows PowerShell, which enables a replacement of ...
Read more