Windows PowerShell is a new command-line shell for system administrators. It is a convenient tool which allows administrators to go through system properties and other settings. As SharePoint administrators, we need to care about properties in Farms, site collections, and sites, as well as additional items from anywhere from one to hundreds of servers.
This is the first post in a series on how users can use comdlets in PowerShell to manage Microsoft SharePoint Server 2010. To write an interesting blog, I would like to include more examples rather than just potentially boring text. Also, I will take some pieces of code from my real work to illustrate how powerful PowerShell is.
Windows PowerShell is a built-in tool in Windows Sever 2008 which contains hundreds of commands. These single-feature commands which manipulate objects are called cmdlets (pronounced “command-lets”) . All of their names are formatted as a verb and a noun separated a dash (-). For example, get-help and get-command and are the most widely used cmdlets in Power Shell, and we will talking about them later.
In SharePoint 2010, SharePoint 2010 Management Shell extends from PowerShell and adds more than 500 SharePoint related cmdlets. That is what I call SharePoint PowerShell. We can open it Start -> All Programs -> Microsoft SharePoint 2010 Products -> SharePoint 2010 Management Shell.
The first cmdlet I’d like to introduce is Get-Help. Just type in get-help and you can see the detailed help information. This is particularly useful when combined with another cmdlet name like:
Next, I would like to introduce the Get-Command cmdlet. This cmdlet will provide you all the commands including cmdlets, functions, and aliases. That would be a loooooooong list, so we can use Piping.
Piping is using a (|) symbol to connect two or more commands which means transfer output from the last command to the next one.
How to use this powerful cmdlet? When we get lost in Power Shell, we should use the get-help cmdlet. The next one can provide you lots of examples:
As SharePoint administrators, we need to take care with Object Modules and Web Service. I take Get-SPSite for example. How can I find this cmdlet? Try Get-Help and Get- Command J
First I would like to print out all the site collections in my sever.
What can we do with this information? The next powerful cmdlet is Get-Member. It will show you all methods and properties in that cmdlet Piping.
Here is an example:
In this example, I get all the site collections in my sever and then use select cmdlet to select URL and Owner properties.
Now let’s end this article with an example to see how we can manipulate these objects only one line script:
I hope you liked this article. In the next one, I plan to post an example to solve a real world problem.
re: Introduction to SharePoint PowerShell
Good introduction. Some more examples can be found here: