Skip to content
Menu
The Lonely Administrator
  • PowerShell Tips & Tricks
  • Books & Training
  • Essential PowerShell Learning Resources
  • Privacy Policy
  • About Me
The Lonely Administrator

Friday Fun: I Can Run that Command in 3 Letters

Posted on May 8, 2015May 8, 2015

Large Blog ImageIf you have been using PowerShell for any length of time, I'm sure you are familiar with aliases. An alias is an alternative name to a PowerShell cmdlet. They are intended to serve as transition aids (like dir and ls) and as a means to keep interactive typing to a minimum. Although with tab completion, if you can get in the habit, perhaps this isn't as big a deal. However, there are a number of aliases you might want consider creating if, like me, you spend a lot of time at a PowerShell prompt.

Manage and Report Active Directory, Exchange and Microsoft 365 with
ManageEngine ADManager Plus - Download Free Trial

Exclusive offer on ADManager Plus for US and UK regions. Claim now!

I still use Notepad, often as a temporary buffer. I'm too lazy to type "notepad" at a prompt. So I have this:

Set-Alias –name np –value $env:WinDir\notepad.exe

I use Set-Alias instead of New-Alias so that if I am trying to define something that already exists I won't get any errors. You can also make your aliases Read-Only so you don't accidently change them.

Set-Alias –name np –value $env:WinDir\notepad.exe –option ReadOnly

Another one that I've started using is an alternative to Select for Select-Object.

set-alias so Select-Object -option ReadOnly

The Name and Value parameters are positional. Like you, I use a number of Office products.

Set-Alias wd "$env:Programfiles\Microsoft Office\Office15\winword.exe" -option ReadOnly
Set-Alias xl "$env:Programfiles\Microsoft Office\Office15\Excel.exe" -option ReadOnly
Set-Alias ie "$env:Programfiles\Internet Explorer\iexplore.exe" -option ReadOnly
Set-Alias pp "$env:Programfiles\Microsoft Office\Office15\Powerpnt.exe" -option ReadOnly

Here's one that might escape my younger readers.

set-alias grok get-help

I have a separate script file that defines all of my aliases which is dot-sourced in my profile script. I use a few Sysinternals utilities and while I could modify %PATH% it is just as easy to create a few aliases.

Set-Alias pe E:\tools\sysinternals\procexp.exe -option ReadOnly
Set-Alias du E:\Tools\Sysinternals\du.exe -Option ReadOnly

My other shortcuts are helper (cheater?) functions like these where the name is more like an alias.

function tm {(get-date).ToLongTimeString()}
function dt {(get-date).ToShortDateString()}

As you can see, I'm using PowerShell aliases for more than cmdlets. What kind of shortcuts and aliases have you come up with?


Behind the PowerShell Pipeline

Share this:

  • Click to share on X (Opens in new window) X
  • Click to share on Facebook (Opens in new window) Facebook
  • Click to share on Mastodon (Opens in new window) Mastodon
  • Click to share on LinkedIn (Opens in new window) LinkedIn
  • Click to share on Pocket (Opens in new window) Pocket
  • Click to share on Reddit (Opens in new window) Reddit
  • Click to print (Opens in new window) Print
  • Click to email a link to a friend (Opens in new window) Email

Like this:

Like Loading...

Related

8 thoughts on “Friday Fun: I Can Run that Command in 3 Letters”

  1. MDafuni says:
    May 8, 2015 at 10:47 am

    These are some the ones I use

    set-alias bx –value Get-Mailbox
    set-alias dg –value Get-Distributiongroup
    set-alias trk –value Get-MessageTrackingLog
    set-alias csu –value Get-CSUser
    set-alias msr –value Get-CsManagementStoreReplicationStatus

    1. Jeffery Hicks says:
      May 8, 2015 at 11:11 am

      Thanks. That last one is practically a requirement.

  2. Zack says:
    May 8, 2015 at 10:25 pm

    I like the notepad one. I know I use ls all the time instead of dir. It gets annoying when I have to use an older system

    1. Jeffery Hicks says:
      May 9, 2015 at 11:01 am

      I often use ps instead get-process. It’s whatever makes it easier for you to get the job done.

  3. Roelof says:
    May 9, 2015 at 9:57 am

    A disadvantage of using your own aliasses is that they only work on your system, not others (unless you define them there too). You tend to forget the commands they replace over time so when not on your own system(s), you have trouble remembering what to type.

    1. Jeffery Hicks says:
      May 9, 2015 at 11:00 am

      To be clear, I never use this in scripts I write. But they are handy shortcuts at the console prompt. And yeah, I’ve caught myself trying to use them when I’m on another computer. Then I laugh at myself.

  4. Bryan Dady says:
    May 9, 2015 at 3:54 pm

    Since I work in an environment where we haven’t yet persuaded everyone that servers (VMs) are cattle and not pets, we don’t yet have PSRemoting pervasively enabled, and so I still need to use Remote Desktop (more than I’d like to). So if I have to use it, I don’t want to spend much time typing out how I want mstsc.exe to behave, so I created a Start-RemoteDesktop function, and included it within my PowerShell Profile scripts (AllUsersAllHosts). I also include an alias in my profile to call Start-RemoteDesktop with my -FullScreen switch Paramater.


    Set-Alias -name rdp -value Start-RemoteDesktop -FullScreen
    # Effectively equivalent to:
    Start-Process -FilePath mstsc.exe -ArgumentList "/v:$ComputerName /Control /fullscreen"

    I also borrowed this PowerShell based telnet alternative from Fabrice ZERROUKI’s example profile (function Test-Port), and add an alias named telnet:


    Set-Alias -name telnet -value Test-Port

  5. Mike Shepard says:
    May 9, 2015 at 4:50 pm

    I like the last example. Haven’t seen using aliases with scriptblocks before. Learn something new every day!

    btw…it was good to talk with you in Chicago.

Comments are closed.

reports

Powered by Buttondown.

Join me on Mastodon

The PowerShell Practice Primer
Learn PowerShell in a Month of Lunches Fourth edition


Get More PowerShell Books

Other Online Content

github



PluralSightAuthor

Active Directory ADSI Automation Backup Books CIM CLI conferences console Friday Fun FridayFun Function functions Get-WMIObject GitHub hashtable HTML Hyper-V Iron Scripter ISE Measure-Object module modules MrRoboto new-object objects Out-Gridview Pipeline PowerShell PowerShell ISE Profile prompt Registry Regular Expressions remoting SAPIEN ScriptBlock Scripting Techmentor Training VBScript WMI WPF Write-Host xml

©2025 The Lonely Administrator | Powered by SuperbThemes!
%d