Tuesday, August 31, 2010

SharePoint 2010 Management Shell: Finding your way around

Windows powershell is new to SharePoint 2010 developers/administrators. In terms of technology and adoption, however, it is the other way around - Powershell has been around for long. Exchange Server, SQL Server have their own management shell on top of PS. 


SharePoint, as is the practice, understandably, takes a while to adopt and use the latest; the Sharepoint snapin and cmdlets comes with the 2010 release. 


It should ideally be bye-bye time to stsadm command now. If not it is a good excuse to create your own custom cmdlet


For new users, it will take a while to get an idea of the power of Powershell; here are a set of tips for finding your way around and getting comfortable with using it


A couple of useful commands that comes in handy everytime for me are get-command and get-help.


Note: if you donot find SP after the hyphen then the cmdlet is not a SharePoint cmdlet and most probably it is available as cmdlet in Windows Poweshell

Let us take the scenario where you have created a farm solution (not sandbox, with 2010 we have to be clearer :)) and is planning to add that to your environment. Do not use stsadm -o addsolution however tempting it turns out to be - look for the corresponding powershell cmdlet


Tip #1: Use Get-Command with wildcards:
You know for sure that cmdlet name will solution, so search for it in SharePoint management shell with
Get-Command *solution*






Tip #2: Use Get-Command with specific command
Now that you have go the cmdlet look closer at to what is its syntax
Get-Command Add-SPSolution 








Tip #3: Use Get-Help with specific command



Get Help is another command you can use, which will say in words and through description (surprisingly good documentation) what the command is all about
Get-Help Add-SPSolution







Tip #4: Use Get-Help with examples switch



In case you need to see some examples on how the command has to be used go for examples switch. 
Get-Help Add-SPSolution -examples



Finally, go ahead and add the solution

You would like the output it gives, right :) Now try to find out how to deploy the solution through cmdlet. Don't be surprised by the output that cmdlet gives (:()



Note: good time to familiarize yourself with the term switch. In powershell there are 3 terminologies used for specifying the inputs to a cmdlet
Parameter : parameter is the name of the cmdlet property for which a value is provided (for e.g. in the Add-SPSolution cmdlet call LiteralPath is a parameter)
Argument : The value that is passed to the parameter (for e.g. in the Add-SPSolution cmdlet call the physical path of the wsp file is the argument)
Switch : the parameter that does not need an argument (for e.g. in the Get-Help cmdlet examples is a switch, imagine turning on a switch and a behavior gets added to the cmdlet)