Monday, January 9, 2012

Best Practice for PowerShell Functions

 

PowerTip of the Day, from PowerShell.com:

This is a best-practice message: when you create your own function, here are some things you should consider:

- Function name: use cmdlet naming syntax (Verb-Noun), and for verbs, stick to the list of approved verbs. For the noun part, use a meaningful English term, and use singular, not plural. So, don't call a function 'ListNetworkCards' but rather 'Get-NetworkCard'


- Company Prefix: To avoid name collisions, all public functions should use your very own noun-prefix. So don't call your function "Get-NetworkCard" because this generic name might be used elsewhere, too. Instead, pick a prefix for your company. If you work for, let's say, 'Global International', a prefix could be 'GI', and your function name would be "Get-GINetworkCard".


- Standard Parameter Names: Stick to meaningful standard parameter names. Don't call a parameter -PC. Instead, call it


-ComputerName. Don't call it -File. Instead, call it -Path. While there is no official list of approved parameter names, you should get familiar with the parameter names used by the built-in cmdlets to get a feeling for it.

 

Thanks

No comments:

Post a Comment