Time to read: around 3 minutes
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-Nounformat, but do use short aliases for chat.
Don’t forget parameters! Want to specify properties?
-pis a nice shorthand for
-property, for example.
I’ve highlighted the sentence that popped out for me.
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
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
This got me thinking, how do we find aliases for parameters?
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 🙂
Get-ParameterAlias -Command ConvertTo-Csv
I wonder if it works on multiple commands, say anything to do with CSVs?
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?
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. 😐