- 1 year ago
Creating Alias in Windows Powershell
To create an alias in Windows PowerShell, you can use the New-Alias
cmdlet. Here's the syntax:
powershellNew-Alias -Name <AliasName> -Value <CommandOrExpression>
Replace <AliasName>
with the desired alias name and <CommandOrExpression>
with the command or expression you want the alias to represent.
Here's an example that creates an alias named ll
for the Get-ChildItem
command (which lists the contents of a directory):
powershellNew-Alias -Name ll -Value Get-ChildItem
Once the alias is created, you can use it as a shorthand for the associated command. In this case, you can use ll
instead of Get-ChildItem
:
powershellll
The output will be the same as running Get-ChildItem
.
Note that aliases created with New-Alias
are temporary and exist only for the current PowerShell session. If you want to create persistent aliases, you can define them in your PowerShell profile script. The profile script is executed automatically when you start PowerShell. To edit your profile script, run the following command:
powershellnotepad $PROFILE
This will open the profile script in Notepad. Add your alias definitions to the profile script, save it, and then restart PowerShell for the changes to take effect.