Getting started with PowerShellLoopsOperatorsUsing ShouldProcessPowerShell ClassesSwitch statementWorking with ObjectsUsing existing static classesBasic Set OperationsPowerShell FunctionsSending EmailHandling Secrets and CredentialsPowershell RemotingPowerShell "Streams"; Debug, Verbose, Warning, Error, Output and InformationVariables in PowerShellCommunicating with RESTful APIsWorking with the PowerShell pipelinePowerShell Background JobsReturn behavior in PowerShellWorking with XML FilesIntroduction to PsakeUsing the progress barStringsTCP Communication with PowerShellSharePoint ModuleAliasesAutomatic VariablesEnvironment VariablesPowershell profilesEnforcing script prerequisitesUsing the Help SystemSplattingDesired State ConfigurationSigning ScriptsSecurity and CryptographyCSV parsingIntroduction to PesterModules, Scripts and FunctionsPowerShell.exe Command-LineCommon parametersParameter setsRegular ExpressionsPowerShell Dynamic ParametersWMI and CIMGUI in PowershellConditional logicURL Encode/DecodeMongoDBRunning ExecutablesError handlingHashTablesActiveDirectory modulepowershell sql queriesAutomatic Variables - part 2Package managementCmdlet NamingBuilt-in variablesCreating DSC Class-Based ResourcesPowershell ModulesPowerShell WorkflowsHow to download latest artifact from Artifactory using Powershell script (v2.0 or below)?Calculated PropertiesSpecial OperatorsAnonymize IP (v4 and v6) in text file with PowershellComment-based helpAmazon Web Services (AWS) Simple Storage Service (S3)Amazon Web Services (AWS) RekognitionPSScriptAnalyzer - PowerShell Script AnalyzerNaming ConventionsEmbedding Managed Code (C# | VB)Archive ModuleInfrastructure AutomationScheduled tasks moduleISE module

Aliases

Other topics

Remarks:

Powershell naming system has quite strict rules of naming cmdlets (Verb-Noun template; see [topic not yet created] for more information). But it is not really convenient to write Get-ChildItems every time you want to list files in directory interactively.
Therefore Powershell enables using shortcuts - aliases - instead of cmdlet names.

You can write ls, dir or gci instead of Get-ChildItem and get the same result. Alias is equivalent to its cmdlet.

Some of the common aliases are:

aliascmdlet
%, foreachFor-EachObject
?, whereWhere-Object
cat, gc, typeGet-Content
cd, chdir, slSet-Location
cls, clearClear-Host
cp, copy, cpiCopy-Item
dir/ls/gciGet-ChildItem
echo, writeWrite-Output
flFormat-List
ftFormat-Table
fwFormat-Wide
gc, pwdGet-Location
gmGet-Member
iexInvoke-Expression
iiInvoke-Item
mv, moveMove-Item
rm, rmdir, del, erase, rd, riRemove-Item
sleepStart-Sleep
start, sapsStart-Process

In the table above, you can see how aliases enabled simulating commands known from other environments (cmd, bash), hence increased discoverability.

Get-Alias

To list all aliases and their functions:

Get-Alias

To get all aliases for specific cmdlet:

PS C:\> get-alias -Definition Get-ChildItem

CommandType     Name                                               Version    Source
-----------     ----                                               -------    ------
Alias           dir -> Get-ChildItem
Alias           gci -> Get-ChildItem
Alias           ls -> Get-ChildItem

To find aliases by matching:

PS C:\> get-alias -Name p*

CommandType     Name                                               Version    Source
-----------     ----                                               -------    ------
Alias           popd -> Pop-Location
Alias           proc -> Get-Process
Alias           ps -> Get-Process
Alias           pushd -> Push-Location
Alias           pwd -> Get-Location

Set-Alias

This cmdlet allows you to create new alternate names for exiting cmdlets

PS C:\> Set-Alias -Name proc -Value Get-Process
PS C:\> proc

Handles  NPM(K)    PM(K)      WS(K) VM(M)   CPU(s)     Id  SI ProcessName
-------  ------    -----      ----- -----   ------     --  -- -----------
    292      17    13052      20444 ...19     7.94    620   1 ApplicationFrameHost
....

Keep in mind that any alias you create will be persisted only in current session. When you start new session you need to create your aliases again. Powershell Profiles (see [topic not yet created]) are great for these purposes.

Contributors

Topic Id: 5287

Example Ids: 18829,18830

This site is not affiliated with any of the contributors.