One of the things that the PowerShell team has always pointed out is the importance of naming conventions in functions. Most of the bult-in PowerShell functions have a verb-noun format i.e. get-process, get-service etc.. Keeping things consistent across the different types of providers helps with the learning process as you can almost guess what a cmdlet would be called once you know the noun.
Up to now I thought this was just a syntax sugar but this blog entry from the main PowerShell guy Jeffrey Snover points out an important benefit if you name your functions correctly.When you type a function name, and PowerShell tries to match the correct code to call, it will automagically add a get- to the function name and try to match on that if it fails to find a function of the exact name.
Heres an example take the simple get-SPSite function
function get-SPSite([string]$url){ new-object Microsoft.SharePoint.SPSite($url)}
I've been using this as $a=get-spsite "http://server" but I could have used $a=spsite "http://server". Its a small thing but if you're typing on the command those extra four characters add up plus it almost looks like C# code not having to use a lengthy namespace prefix.
Likewise for get-SPWeb
function get-SPWeb([string]$url){ $site=new-object Microsoft.SharePoint.SPSite($url)
$site.OpenWeb()}
Powered by: newtelligence dasBlog 2.0.7226.0
Disclaimer The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.
© Copyright 2010, Colin Byrne
E-mail