Skip Ribbon Commands
Skip to main content
Sign In
SharePoint Program Manager, Infrastructure
Zach Rosenfield's SharePoint Blog > Posts > PowerShell 2010: Basic SharePoint Cmdlets
October 29
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?
 on 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 RosenfieldNo presence information on 11/5/2009 1:19 PM

ReACL Permissions

Hi Zach,

  I am working on migrating MOSS 2007 to SP 2010 and we need to move all the permissions from the 2007[AD accounts] environment to 2010[Global LDAP directory accounts].  Can we use PS to write scripts which can do this work? or do we have to write custom code with SP to do this? Any help will be greatly appreciated.

Thank you very much.

Regards
Vishwas
 on 6/17/2010 5:23 AM

powershell's power

how do you create sharepoint webpart page using powershell?
 on 6/22/2010 4:27 AM

Re: PowerShell 2010: Basic SharePoint Cmdlets

Nice quick post, definitly some quick cmdlets to use to scope or investigate an environment that a client already has setup.

I will keep an eye on your blog.
 on 8/20/2010 8:15 AM

PowerShell magic

Wow, Zach good work.
My first thought when I heared about PS was Oh My God now I have to learn so many new commands. But after reading your post My thoughts are "Cool, this is strong magical stuff".

Thanks
 on 11/25/2010 10:31 AM

Hiii All

Hii I am deepak chauhan from Mohali.Please send me all powe shell command

Thanks & Regard
Deepak chauhan
deepak.mit.cs@gmail.com
 on 11/8/2012 4:08 AM

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) *


Human Test


Checking if you're human: enter "1234" (no quotes)

Attachments