Over the last few weeks I’ve been working with a vendor to improve the usability of their PowerShell module.
For vendors there is a tool which allows you to automatically create a PowerShell module 🙂
This is some very cool stuff, but it takes over the name of properties as they are created in the classes.
So normally a manual review should be desired, at least the first time you generate your module.
They kinda forgot to do that 🙂
I also looked at the module to apply some PowerShell Best Practices. For example, parameters should never be named after the plural.
How can you discover those? How can you find parameters named after the plural?
There is no property for that, so you would have to make some educated guesses.
In the English language, most plurals end with an ‘s’. Sometimes even two.
With that in mind, here is some code that allows you to find parameters that probably have been named after the plural 🙂
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
$Modules = Get-Module -ListAvailable foreach ($Module in $Modules) { $Commands = get-command -Module $Module.Name foreach ($Command in $Commands) { $Parameters = $Command.Parameters foreach ($Parameter in $Parameters) { $Parameter.Keys | foreach { switch ($Parameter.Values) { {$_ -eq 'Verbose'} {break;} {$_ -eq 'Debug'} {break;} {$_ -eq 'ErrorAction'} {break;} {$_ -eq 'WarningAction'} {break;} {$_ -eq 'ErrorVariable'} {break;} {$_ -eq 'WarningVariable'} {break;} {$_ -eq 'OutVariable'} {break;} {$_ -eq 'OutBuffer'} {break;} {$_ -eq 'PipelineVariable'} {break;} default { if (($_ -notlike "*ss") -and ($_ -like "*s")) { [pscustomobject]@{ ModuleName = $Module.Name CommandName = $Command.Name ParameterName = $_ } } } } } } } } |