New-Alias

New-Alias – A Simple Way To Rename Your Workflow in PowerShell

Welcome back to Wahmans Powershell Blog! Today we’re diving into a cmdlet that is often overlooked, yet incredibly handy when you’re scripting in PowerShell: New-Alias. According to Microsoft, New-Alias “creates a new alias,” and while that sounds simple, the implications for productivity are powerful.

Aliases let us create alternative names for existing cmdlets or scripts. Maybe you come from a Linux background and want to use familiar commands, or maybe you simply want to shorten long command names. New-Alias to the rescue!

Basic Syntax

New-Alias <AliasName> <CommandName>

Examples

Example 1: Beginner – Creating a Shortcut for Get-ChildItem

If you’re tired of typing Get-ChildItem over and over, create an alias:

New-Alias -Name gci -Value Get-ChildItem

From now on, you can just type gci instead of Get-ChildItem. Much faster!

Example 2: Intermediate – Aliasing a Script

Let’s say you have a script C:\Scripts\Update-Reports.ps1 that you run often. First, you can dot-source it and then alias it:

Function Run-Reports { & C:\Scripts\Update-Reports.ps1 }
New-Alias -Name ur -Value Run-Reports

Now, just run ur in your console to execute the report update script.

Example 3: Advanced – Overriding Existing Cmdlets Carefully

WARNING: Proceed with caution! You can use New-Alias to override existing commands, like so:

New-Alias -Name ls -Value Get-ChildItem

This is helpful if you are transitioning from a Unix-like shell to PowerShell and want to use ls as you would in bash. Remember, this does not persist between sessions unless saved in your Profile.ps1.

Example 4: Advanced – Using Aliases Across Sessions

To make an alias permanent, add it to your PowerShell profile:

notepad $PROFILE

Then add:

New-Alias -Name sd -Value Set-Location

Now sd will work every time you start PowerShell!

Final Thoughts

New-Alias is a simple yet powerful cmdlet that can save time, reduce typing, and improve your scripting efficiency. Just remember that aliases do not persist across sessions unless explicitly saved—and some might obscure readability in shared scripts.

Happy scripting, and I will see you in the next post!

Leave a Reply

Your email address will not be published. Required fields are marked *