You should now have a good foundation to start working with PowerShell. You'll find that PowerShell offers the following advantages over STSADM:
- Looping – The ability to work through a collection of objects (web applications, site collections, web, users, and so on) and perform an action on each one.
- Filtering – Being able to loop through a specific set of objects, like webs that are based on the blog template, or users whose names start with “T.”
- Piping – The ability to pass objects from one command to another, allowing some very complicated tasks to be completed in a single command line.
- Access to the object model – PowerShell gives you direct access to the method and properties of SharePoint’s objects
Here are a few other PowerShell snippets to get your creative juices flowing:
This command lists all the databases in your farm in order of largest to smallest and shows their size.
Get-SPDatabase | sort-object disksizerequired -desc | format-table Name, @{Label ="Size in MB"; Expression = {$_.disksizerequired/1024/1024}}
This command backs up each of your site collections to c:\backups and automatically names them.
Get-SPWebApplication | Get-SPSite | ForEach-Object {$FilePath = “c:\backups\” + $_.Url.Replace("http://",””).Replace(“/”,”-“ + “.bak”; Backup-SpSite –Identity $_ -path $Filepath}
This command enables a Feature on every site collection in a given web application.
Get-SPSite –Limit ALL –WebApplication $WebAppNameorUrl |%{ Enable-SPFeature $FeatureIdOrName –url $_.Url }
I hope this article has made you more comfortable with using PowerShell in your SharePoint 2010 farm. The best way to get familiar with PowerShell is not by reading articles like this one (although it’s a great start); the best way is to start using PowerShell.
The next time you need to accomplish a task in SharePoint 2010, make a conscious effort to learn how to do it in PowerShell. The first few times will be painful, but very soon you’ll get used to how PowerShell works and it will become second nature to you.