Have you ever spent an afternoon setting site collection properties manually on every site collection in your farm? How about going through and activating features following an upgrade? These are just two simple examples of where PowerShell can turn an entire afternoon worth of work into just a few minutes. In this session we’ll start off with a familiarization of PowerShell and progress into capabilities and usage scenarios of the out of the box SharePoint 2010 cmdlets.
Presented at SharePoint Saturday, Virginia Beach (January 7, 2012)
3. AGENDA
• What is PowerShell
• Working with PowerShell
• When to Use PowerShell
• Top 10 SharePoint 2010 Cmdlets
• Using the PowerShell Pipeline
• User Scenarios
• Tools & Resources
1/7/2012 Making Life Easier with PowerShell 3
4. Core Concepts
WHAT IS POWERSHELL
1/7/2012 Making Life Easier with PowerShell 4
5. WHAT IS POWERSHELL
• Microsoft task automation framework built on the .NET framework
• Command-line shell
• Scripting language (*.ps1)
• Common “shell” to Microsoft technologies (AD, SQL, SP, Server, etc.)
• Full access to COM (Component Object Model) and WMI (Windows
Management Instrumentation) for local and remote system
management
• Replacement to STSADM (deprecated)
• PowerShell > STSADM
• All STSADM operations have a PowerShell equivalent
• Integrated support for multiple platforms/services (not SP specific)
• Easily Extendable
1/7/2012 Making Life Easier with PowerShell 5
6. Core Concepts
WORKING WITH POWERSHELL
1/7/2012 Making Life Easier with PowerShell 6
7. POWERSHELL SNAP-INS
• PowerShell snap-in registers sets of cmdlets and/or providers,
extending the default functionality of the shell
• Similar to a web browser plug-in
• Added and removed as needed during user session
1/7/2012 Making Life Easier with PowerShell 7
8. POWERSHELL CMDLETS
• A cmdlet (“command-let”) is a specific command executed in the
PowerShell environment
• Following a common {verb}-{noun} naming convention, cmdlet
functions are typically easily understood, ie: Add-PSSnapin, Get-
SPWeb, etc.
• Used like a function, cmdlets take one or more input
parameters/objects, and output objects or arrays of objects
• Cmdlets can be piped together, allowing the output object of one to
become the input object of another
• Objects are always processed individually, if multiple input objects are
specified, each object will be fully processed before the next is begun
1/7/2012 Making Life Easier with PowerShell 8
9. WHEN TO USE POWERSHELL
• Making life “easier” with PowerShell should equate to increased
efficiency, lower cost, and lower turnaround
• Identify those processes which are repetitive in nature or those that
require extended “hands-on” time
1/7/2012 Making Life Easier with PowerShell 9
10. GETTING STARTED
SharePoint 2010
Management Shell
PowerShell with the
SharePoint Snap-in Loaded
1/7/2012 Making Life Easier with PowerShell 10
11. STARTING POWERSHELL
PowerShell 2.0
1/7/2012 Making Life Easier with PowerShell 11
12. Demonstration
CREATE A POWERSHELL PROFILE
1/7/2012 Making Life Easier with PowerShell 12
13. SharePoint 2010
TOP 10 POWERSHELL CMDLETS
1/7/2012 Making Life Easier with PowerShell 13
14. GET-HELP
• Overview
• Displays help about Windows PowerShell cmdlets and concepts
• Examples
• Get-Help {cmdlet}
• Get-Help Test-Path
• Get-Help Test-Path -Detailed
• Get-Help Test-Path –Examples
• Get-Help {topic}
• Get-Help Snapin
1/7/2012 Making Life Easier with PowerShell 14
15. GET-MEMBER
• Overview
• Gets the properties and methods of objects. Specify an object
using the InputObject parameter, or pipe an object to Get-Member.
• Examples
• Get-Member –InputObject $object
• $object | Get-Member
1/7/2012 Making Life Easier with PowerShell 15
16. GET-SPFARM
• Overview
• Returns the local SharePoint farm.
• Examples
• Get-SPFarm
• $farm = Get-SPFarm
$farm.Properties
1/7/2012 Making Life Easier with PowerShell 16
17. GET-SPWEBAPPLICATION
• Overview
• Returns all web applications that match the given criteria. If no
identity is specified, all web applications are returned. The Central
Administration web application is ignored unless specified directly
or the IncludeCentralAdministration flag is specified.
• Examples
• Get-SPWebApplication
• Get-SPWebApplication –IncludeCentralAdministration
• Get-SPWebApplication http://intranet
1/7/2012 Making Life Easier with PowerShell 17
18. GET-SPSITE
• Overview
• Returns all the site collections that match the given criteria. If no
identity is specified, the farm is scope is used.
• Examples
• Get-SPSite
• Get-SPSite http://intranet
• Get-SPSite http://intranet/depts/facilities
1/7/2012 Making Life Easier with PowerShell 18
19. GET-SPWEB
• Overview
• Returns all subsites that match the given criteria.
• Examples
• Get-SPWeb http://intranet/depts/HR/benefits
• Get-SPWeb http://intranet/depts/HR/*
• Get-SPWeb http://intranet/* –filter {$_.Template –eq “STS#0”}
1/7/2012 Making Life Easier with PowerShell 19
20. GET-SPSERVICEAPPLICATION
• Overview
• Returns the specified service application. If no service application
is specified, all are returned.
• Examples
• Get-SPServiceApplication
• Get-SPServiceApplication | select Name, Status
1/7/2012 Making Life Easier with PowerShell 20
21. GET-SPCONTENTDATABASE
• Overview
• Returns one or more content databases.
• Examples
• Get-SPContentDatabase
• Get-SPContentDatabase –WebApplication http://intranet
• Get-SPContentDatabase –Site http://intranet
1/7/2012 Making Life Easier with PowerShell 21
22. TEST-SPCONTENTDATABASE
• Overview
• Tests a content database against a web application to verify all
customizations referenced within the content database are also
installed in the web application. Content databases do not need to
be mounted for validation to complete.
• Examples
• Test-SPContentDatabase –name Lab_Content_Intranet
–WebApplication http://intranet
1/7/2012 Making Life Easier with PowerShell 22
23. EXPORT-CLIXML & EXPORT-CSV
• Overview • Overview
• Creates an XML-based • Converts objects into a
representation of an series of comma-
object or objects & stores separated value strings &
in a file. saves file.
• Examples • Examples
• $sites = Get-SPSite • $sites = Get-SPSite
Export-Clixml -InputObject Export-CSV -InputObject
$sites -Path $sites -Path
c:sites.xml c:sites.csv
• Get-SPSite | Export-Clixml • Get-SPSite | Export-CSV
c:sites.xml c:sites.csvs
1/7/2012 Making Life Easier with PowerShell 23
24. Demonstration
LIST ALL SHAREPOINT CMDLETS
1/7/2012 Making Life Easier with PowerShell 24
25. POWERSHELL PIPELINE
• The use of the PowerShell Pipeline allows the output object of one cmdlet
to become the input object of another
• “Piping” is performed by using the pipe character “ | ” between cmdlets
• Applies to native cmdlets (such as sorting, logical operations, and data
manipulation) and functional cmdlets (such as those for SharePoint)
• Logical Example:
Get-SPContentDatabase -WebApplication http://intranet | Where
{$_.CurrentSiteCount -gt 5}
• Functional Example:
Get-SPSite http://intranet | Get-SPWeb | Enable-SPFeature -Identity
“MyFeature”
1/7/2012 Making Life Easier with PowerShell 25
26. Demonstration
USER SCENARIOS
1/7/2012 Making Life Easier with PowerShell 26
27. TOOLS & RESOURCES
• Tools
• Windows PowerShell Integrated Scripting Environment (ISE)
• Idera PowerShell Plus (free trial available)
• Resources
• STSADM -> PowerShell Mapping
http://technet.microsoft.com/en-us/library/ff621081.aspx
• Scripting with Windows PowerShell (5 part webcast series)
http://technet.microsoft.com/en-us/scriptcenter/dd742419
• PowerShell Power Hour (monthly lunchtime webcasts)
http://idera.com/Education/PowerShell-Webcasts/
• SP2010 Visual PowerShell Command Builder
http://www.microsoft.com/resources/TechNet/en-
us/Office/media/WindowsPowerShell/WindowsPowerShellCommandBuilder.ht
ml
• Automating Microsoft SharePoint 2010 Administration with Windows
PowerShell 2.0. Gary Lapointe, Shannon Bray
• Automating Microsoft Windows Server 2008 R2 Administration with Windows
PowerShell 2.0. Matthew Hester, Sarah Dutkiewicz
1/7/2012 Making Life Easier with PowerShell 27