Finding Aliases for Parameters in PowerShell

Going concise as possible WAS bad practice at one stage!

Words: 443

Time to read: around 3 minutes

I’ve been wanting to get into ChatOps for a while now and so when Warren Frame’s ( blog | twitter ) post on PoshBot Usability popped up on my post feed, I dived into it.

One of the practices that Warren mentions is to “[…] Keep it short.”

Verbosity is king in PowerShell. With no tab completion to help discovery and spelling? Keep it short! Reserve single character aliases for your most popular commands and parameters. Expand as needed. Again, you can always leave the actual command name in a PowerShell Verb-Noun format, but do use short aliases for chat.

Don’t forget parameters! Want to specify properties? -p is a nice shorthand for -property, for example.

I’ve highlighted the sentence that popped out for me.

Function Aliases:

Now I knew that you could give a function an alias. I even do that for one of the functions I created and use; the one that tells me how long a video lasts if I watch at different speeds.

In case you were wondering, the specific section is this bit; I’ve added a comment # <-- where it can be found

function Get-VideoPlayBackTime {
comment based help
[Alias('video')] # <– This guy!
param (
# Minutes of the video only
[Parameter(Position = 0)]
[int]$Minutes = 0,
# Seconds of the video left over after minutes
Position = 1)]
# Speed up value for the video defaulting to 1.5
[Parameter(Position = 3)]
[ValidateSet('0.25', '0.5', '0.75', '1', '1.25', '1.5', '2')]
[double]$SpeedUp = 1.5
the rest of the code

That, however, is to give the entire function an alias. In this case, rather than type out Get-VideoPlayBackTime -Minutes etc, I can just type video -minutes etc.
Handy when you’re running it sporadically at the command line.

Warren mentions parameter aliases though and gives great examples in his other post about getting started with PoshBot.

Again, look for the # <--

function name
comment based help
[parameter(position = 1,
parametersetname = 'id')]
[parameter(position = 1,
parametersetname = 'filter')]
[Alias('l')] # <– LDAPFilter? Just type 'l'
[parameter(position = 2)]
[string[]]$Properties, # <– Properties? Nah, type 'p'
[string]$Format = 'list' # <– Format? Pfft! Try 'f'
The rest of the code

This got me thinking, how do we find aliases for parameters?

Parameter Aliases:

I tried looking in the help file but, taking ConvertTo-Csv as an example, there’s no mention of an alias that I can see in there (Get-Help -Name ConvertTo-Csv -Full).

So time to whip up a function 🙂

function Get-ParameterAlias {
param (
[Parameter(Position = 0)]
begin {
process {
Write-Verbose Message "[PROCESS] Checking parameter aliases for [$_]…"
foreach ($cmd in (Get-Command Name $Command CommandType Function).Name) {
$cmdObject = Get-Command Name $cmd
$cmdObject.Parameters.Values |
ForEach-Object Process {
Command = $cmd
Parameterr = $_.Name
Alias = $_ | Select-Object ExpandProperty Aliases
end {

Running: Get-ParameterAlias -Command ConvertTo-Csv

NoTypeInformation = NTI ???

Sweet as!

I wonder if it works on multiple commands, say anything to do with CSVs?

Running: Get-ParameterAlias -Command *CSV


Since I’d mainly be thinking of using ChatOps on databases, and I mainly use the dbatools module, does it work on that?

Running: Get-ParameterAlias -Command (Get-Command -Module dbatools -CommandType Function) | Select-Object -First 50


Still a bit long for ChatOps but they’re there, this works, and I can always create a pull request on Github for them!


Yes, I know the function isn’t finished; no comment based help, verbose writing, or examples; and I’m painfully aware that a function about finding parameter aliases doesn’t have any parameter aliases itself. 😐

But hey! Feel free to help mature this out over on Github and help out. That goes for creating issues and pull requests on dbatools as well!

Author: Shane O'Neill

DBA, T-SQL and PowerShell admirer, Food, Coffee, Whiskey (not necessarily in that order)...

One thought on “Finding Aliases for Parameters in PowerShell”

Leave a Reply

%d bloggers like this: