If 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.
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?
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
Thanks. That last one is practically a requirement.
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
I often use ps instead get-process. It’s whatever makes it easier for you to get the job done.
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.
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.
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
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.