August 31, 2010 10:45 AM

Learn How to Manage SharePoint with PowerShell

With practice, PowerShell will become your best friend
SharePoint Pro
InstantDoc ID #125513
Rating: (3)

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.

Related Content:

ARTICLE TOOLS

   
Comments
  • Van De Sande
    1 year ago
    Jan 03, 2011

    Thanks for the article! Just learning there was such a thing as Get-Member made my life so much easier.

You must log on before posting a comment.

Are you a new visitor? Register Here
   
   

Dan Holme's Viewpoint on SharePoint Blog

Office 365 Plan for Pain

With cloud services, even Office 365, what you don’t know about your cloud service can hurt you,...

SharePoint News and Products

Let SharePoint Be SharePoint: Making Social Collaboration Secure

Hesitant about unleashing SharePoint's social features? SharePoint security vendors aim to help....

Dan Holme's Viewpoint on SharePoint Blog

Microsoft SkyDrive Updates in the News

Microsoft's cloud storage, sharing, and collaboration platform for Windows Live is updated,...