Interpreting Standard Aliases

07/25/2009

Unlike the aliases described above, which were designed for name-compatibility with other interfaces, the aliases built into Windows PowerShell are generally designed for brevity. These shorter names can be typed quickly, but are impossible to read if you do not know what they refer to.

Windows PowerShell tries to compromise between clarity and brevity by providing a set of standard aliases that are based on shorthand names for common verbs and nouns. This allows a core set of aliases for common cmdlets that are readable once you know the shorthand names. For example, in standard aliases the verb Get is abbreviated to g, the verb Set is abbreviated to s, the noun Item is abbreviated to i, the noun Location is abbreviated to l, and the noun Command is abbreviated to cm.

Here is a brief example to illustrate how this works. The standard alias for Get-Item comes from combining g for Get and i for Item: gi. The standard alias for Set-Item comes from combining s for Set and i for Item: si. The standard alias for Get-Location comes from combining g for Get and l for Location, gl. The standard alias for Set-Location comes from combining s for Set and l for Location, sl. The standard alias for Get-Command comes from combining g for Get and cm for Command, gcm. There is no Set-Command cmdlet, but if there were, we would be able to guess that the standard alias comes from s for Set and cm for Command: scm. Furthermore, people familiar with Windows PowerShell aliasing who encounter scm would be able to guess that the alias refers to Set-Command.

Creating New Aliases

You can create your own aliases using the Set-Alias cmdlet. For example, the following statements create the standard cmdlet aliases discussed in Interpreting Standard Aliases:

Set-Alias -Name gi -Value Get-Item

Set-Alias -Name si -Value Set-Item

Set-Alias -Name gl -Value Get-Location

Set-Alias -Name sl -Value Set-Location

Set-Alias -Name gcm -Value Get-Command

Internally, Windows PowerShell uses commands like these during startup, but these aliases are not changeable. If you attempt to actually execute one of these commands, you will get an error explaining that the alias cannot be modified. For example:

PS> Set-Alias -Name gi -Value Get-Item

Set-Alias : Alias is not writeable because alias gi is read-only or constant and cannot be written to.

At line:1 char:10

+ Set-Alias <<<< -Name gi -Value Get-Item

Posted in: Others Software| Tags: Interpreting Standard Alias Describe Set-Commad Encounter Scm Furthermore Familiar

Hot Posts

Latest posts

Tags

Others

Sponsors

asp.net interview questions