Hyphens in Command Names

In my previous blog entry, I talked about how Michael Fisher had blogged his intial impressions about PowerShell.


One of the things that Michael did not like was the hyphenated command names.  A discussion about the Pros/Cons of hyphens isn’t actionable at this point because we’ve placed our bets and shipped V1.  Even if there was a compelling argument that convinced me of the errors of my ways, I wouldn’t be able to do anything about it.    Changing would break compatibility.


Now that isn’t to say, “take it or leave it”.   No no no no.  This is a customizable shell.  In fact, it is an EASILY customizable shell.  (There’s a difference between those 2).


Michael – I encourage you to see if you can come to terms with the our hyphens.  I’m told that everyone blanches the first time they taste Scotch but if you give it chance, you can grow a deep and profound appreciation for it.  On the other hand, if you are like me and hate the stuff (me=>Scotch, you=>hyphenated commands) after repeated attempts to “see the magic”, all you need to do is to put the following line in your startup profile:


Get-Command -Type Cmdlet | %{ Set-Alias ($_.Name -replace “-” ) $_.Name}


Give that a try and see how you like it.  If you want to see what is going on, just add a -Verbose to the Set-Alias:


PS> Get-Command -Type Cmdlet |%{Set-Alias ($_.Name -Replace “-“) $_.Name -verbose}
VERBOSE: Performing operation “Set Alias” on Target “Name: AddContent Value: Add-Content”.
VERBOSE: Performing operation “Set Alias” on Target “Name: AddHistory Value: Add-History”.
VERBOSE: Performing operation “Set Alias” on Target “Name: AddMember Value: Add-Member”.
VERBOSE: Performing operation “Set Alias” on Target “Name: AddPSSnapin Value: Add-PSSnapin”.
VERBOSE: Performing operation “Set Alias” on Target “Name: ClearContent Value: Clear-Content”.
VERBOSE: Performing operation “Set Alias” on Target “Name: ClearItem Value: Clear-Item”.
VERBOSE: Performing operation “Set Alias” on Target “Name: ClearItemProperty Value: Clear-ItemProperty”.
VERBOSE: Performing operation “Set Alias” on Target “Name: ClearVariable Value: Clear-Variable”.
VERBOSE: Performing operation “Set Alias” on Target “Name: CompareObject Value: Compare-Object”.
VERBOSE: Performing operation “Set Alias” on Target “Name: ConvertFromBase64 Value: ConvertFrom-Base64″.

…….


Be aware that if you write scripts using these aliases, you won’t be able to share them with other people and have them “just work”.  That is the tension between customization and community.  You are empowered to make your own decision about how to resolve that tension. 


Welcome to the community Michael – keep on blogging! 


Jeffrey Snover [MSFT]
Windows PowerShell/MMC Architect
Visit the Windows PowerShell Team blog at:    http://blogs.msdn.com/PowerShell
Visit the Windows PowerShell ScriptCenter at:  http://www.microsoft.com/technet/scriptcenter/hubs/msh.mspx