Sign In
 
 
Go Search
 
Zach Rosenfield's SharePoint Blog > Posts > PowerShell 2010: Basic SharePoint Cmdlets
PowerShell 2010: Basic SharePoint Cmdlets

Two important notes for all future PS+SP posts before i begin to give some SharePoint specific cmdlets:

 

First, make sure if you've added any of my "V3/2007" Scripts to your environment to remove them! Functions "Outweigh" cmdlets so you'll be getting "strange" behavior if you load these!

 

Second, i am doing examples to show you possibilities.  Unless i say "always do things this way" or "never do things this way"--then I’m not demonstrating a 'best practice'.  Please don't assume that I will always show the "best" way--just one option.  I'll happily add any alternatives people suggest.

 

With that in mind, here are some starter "SP+PS" samples...

 

1. Get the local farm:

PS> Get-SPFarm

 

2. Get All details of the farm (default is a limited "formatted" view):

PS> Get-SPFarm | Select *

 

3. Get all web applications in the farm:

PS> Get-SPWebApplication

 

4. Get all web applications including Central Administration (CA) web applicaiton:

PS> Get-SPWebApplication -IncludeCentralAdministration

 

5. Get all site collections in the farm (across all web applications, but NOT including CA):

PS> Get-SPSite -Limit All

 

*Note the "limit" parameter.  By default we limit to 20 site collections as "listing all cmdlets" can be a 'large' operation that you should be very aware of doing...

 

6. Use WhatIf to "see what will happen".  No more "run and hope"!

PS> Get-SPSite -Limit All | Remove-SPSite -whatif

 

7. "Destructive" cmdlets will prompt by default (provided the Environment's "Prompt" defaults have not been lowered!)

PS>Remove-SPSite http://contoso

 

8. Prompts can be "suppressed" using "-Confirm:$False" (not recommended!):

PS>Remove-SPSite http://contoso -Confirm:$False

 

*NOTE: "Success" in PowerShell is "No" output.  When an error or warning occurs it will print to screen--ErrorAction, ErrorVariable, WarningAction, and WarningVariable can be used to "script" handling these outputs.

 

As usual, more advanced stuff coming soon!

Comments

Get-SPSite question

Hi Zach,

are the SharePoint Cmdlets just a thin layer on top of the SharePoint API? In other words, is it the case that everything you can do through Cmdlets can be done by myself through the API?

I am interested in one specific example. I see that Get-SPSite allows you to pass a regex pattern to filter on the url of the SPSite. Is this something that can be done using the SharePoint API, without me having to loop through a collection of SPSites and performing the regex testing? Or is that what the Cmdlet is doing internally?
at 11/2/2009 6:00 AM

Re: Get-SPSite question

The best way to think of PowerShell Cmdlets is that they are "a bunch of small tools" that are available to admins--while they are built ontop of the APIs, commands that are part of the Foundation Product are used to sometimes control functionality that is only for administrators, and not intended for development.

The "server side filtering" (post on this coming next week) features are for PowerShell only.  This was built specifically for administrator usage and was not implemented in a way that was intended for Developers to use outside of PowerShell.

Thanks,
Zach
Zach Rosenfield at 11/5/2009 1:19 PM

Add Comment

Items on this list require content approval. Your submission will not appear in public views until approved by someone with proper rights. More information on content approval.

Title


Comments *


Name (required) *


Attachments
 
 
   
Real Time Web Analytics