![Page 1: Introduction to PowerShell for SharePoint Admins and Developers - SharePoint Fest Chicago 2013 SIA101](https://reader033.vdocuments.us/reader033/viewer/2022061119/546ac084af795920668b4bd1/html5/thumbnails/1.jpg)
Introduction to PowerShell for SharePoint Developers and
Administrators
SIA 101
Michael BlumenthalPSC Group, LLC
![Page 2: Introduction to PowerShell for SharePoint Admins and Developers - SharePoint Fest Chicago 2013 SIA101](https://reader033.vdocuments.us/reader033/viewer/2022061119/546ac084af795920668b4bd1/html5/thumbnails/2.jpg)
2
Who is Michael Blumenthal?
Sr. Solution Architectat PSC Group
CSPUG Co-LeaderINETA Champ 2010-201318 years in IT Consulting10 years working with
SharePoint (2003,2007,2010, 2013)
![Page 3: Introduction to PowerShell for SharePoint Admins and Developers - SharePoint Fest Chicago 2013 SIA101](https://reader033.vdocuments.us/reader033/viewer/2022061119/546ac084af795920668b4bd1/html5/thumbnails/3.jpg)
3
This is about you
Version of SharePoint?Admin, Developer, Both, Other?PowerShell experience?SharePoint experience?Unix experience?Scripting experience?
![Page 4: Introduction to PowerShell for SharePoint Admins and Developers - SharePoint Fest Chicago 2013 SIA101](https://reader033.vdocuments.us/reader033/viewer/2022061119/546ac084af795920668b4bd1/html5/thumbnails/4.jpg)
4
No Compiling!
No Packaging!
Just Code & Go!
Why PowerShell?
![Page 5: Introduction to PowerShell for SharePoint Admins and Developers - SharePoint Fest Chicago 2013 SIA101](https://reader033.vdocuments.us/reader033/viewer/2022061119/546ac084af795920668b4bd1/html5/thumbnails/5.jpg)
5
PowerShell puts the SharePoint Engine at your fingertips!
• It’s Easy to Get Started!1• Learn the PowerShell Syntax2• Real World Examples3• More Resources4• Q&A & Raffle5
![Page 6: Introduction to PowerShell for SharePoint Admins and Developers - SharePoint Fest Chicago 2013 SIA101](https://reader033.vdocuments.us/reader033/viewer/2022061119/546ac084af795920668b4bd1/html5/thumbnails/6.jpg)
6
Chapter 1
IT’S EASY TO GET STARTED!
![Page 7: Introduction to PowerShell for SharePoint Admins and Developers - SharePoint Fest Chicago 2013 SIA101](https://reader033.vdocuments.us/reader033/viewer/2022061119/546ac084af795920668b4bd1/html5/thumbnails/7.jpg)
Getting Started with PowerShell
Windows Server 2003• Download
Windows Server 2008• Install
Server2008 R2, 2012, Win8• Run (Add ISE)
![Page 8: Introduction to PowerShell for SharePoint Admins and Developers - SharePoint Fest Chicago 2013 SIA101](https://reader033.vdocuments.us/reader033/viewer/2022061119/546ac084af795920668b4bd1/html5/thumbnails/8.jpg)
8
![Page 9: Introduction to PowerShell for SharePoint Admins and Developers - SharePoint Fest Chicago 2013 SIA101](https://reader033.vdocuments.us/reader033/viewer/2022061119/546ac084af795920668b4bd1/html5/thumbnails/9.jpg)
9
![Page 10: Introduction to PowerShell for SharePoint Admins and Developers - SharePoint Fest Chicago 2013 SIA101](https://reader033.vdocuments.us/reader033/viewer/2022061119/546ac084af795920668b4bd1/html5/thumbnails/10.jpg)
10
V2
![Page 11: Introduction to PowerShell for SharePoint Admins and Developers - SharePoint Fest Chicago 2013 SIA101](https://reader033.vdocuments.us/reader033/viewer/2022061119/546ac084af795920668b4bd1/html5/thumbnails/11.jpg)
11
PowerShell V3 ISE
![Page 12: Introduction to PowerShell for SharePoint Admins and Developers - SharePoint Fest Chicago 2013 SIA101](https://reader033.vdocuments.us/reader033/viewer/2022061119/546ac084af795920668b4bd1/html5/thumbnails/12.jpg)
12
POSH vs the SharePoint Mgmt Shell
![Page 13: Introduction to PowerShell for SharePoint Admins and Developers - SharePoint Fest Chicago 2013 SIA101](https://reader033.vdocuments.us/reader033/viewer/2022061119/546ac084af795920668b4bd1/html5/thumbnails/13.jpg)
13
Chapter 2
LEARN THE POWERSHELL SYNTAX!
![Page 14: Introduction to PowerShell for SharePoint Admins and Developers - SharePoint Fest Chicago 2013 SIA101](https://reader033.vdocuments.us/reader033/viewer/2022061119/546ac084af795920668b4bd1/html5/thumbnails/14.jpg)
Learn to use PowerShell with SharePoint!
Symbols & Keywords
Using the SharePoint API
Creating and Running Scripts
![Page 15: Introduction to PowerShell for SharePoint Admins and Developers - SharePoint Fest Chicago 2013 SIA101](https://reader033.vdocuments.us/reader033/viewer/2022061119/546ac084af795920668b4bd1/html5/thumbnails/15.jpg)
15
Symbols, Keywords, and Syntax! Oh My!
• Variables1• Commands2• Piping3• Comparisons4• Flow Control5• Filtering6
![Page 16: Introduction to PowerShell for SharePoint Admins and Developers - SharePoint Fest Chicago 2013 SIA101](https://reader033.vdocuments.us/reader033/viewer/2022061119/546ac084af795920668b4bd1/html5/thumbnails/16.jpg)
16
Punctuation PronunciationSymbol Called Symbol Called
$ Dollar sign, money _ Underscore
# Hash, Pound [ ] Square Brackets
| Pipe, vertical bar . Dot, point, period
{ } Curly braces < > Angle Brackets
“ Double Quote, tick - Dash, hyphen, minus
: Colon % Percent sign
( ) Parentheses ; Semi-colon
+ Plus = Equals, is
! Bang, not /, \ Slash, backslash
1$#|
![Page 17: Introduction to PowerShell for SharePoint Admins and Developers - SharePoint Fest Chicago 2013 SIA101](https://reader033.vdocuments.us/reader033/viewer/2022061119/546ac084af795920668b4bd1/html5/thumbnails/17.jpg)
17
Variables begin with a $
• Case Insensitive, Dynamic typing
$foo
$true, $false, $profile, $null
$foo = “Hello, World”
1
![Page 18: Introduction to PowerShell for SharePoint Admins and Developers - SharePoint Fest Chicago 2013 SIA101](https://reader033.vdocuments.us/reader033/viewer/2022061119/546ac084af795920668b4bd1/html5/thumbnails/18.jpg)
18
![Page 19: Introduction to PowerShell for SharePoint Admins and Developers - SharePoint Fest Chicago 2013 SIA101](https://reader033.vdocuments.us/reader033/viewer/2022061119/546ac084af795920668b4bd1/html5/thumbnails/19.jpg)
19
Commands are called cmdlets.
Verb-Noun
Built-in, Extensible
Get-Help & Help
Get-Member
2
![Page 20: Introduction to PowerShell for SharePoint Admins and Developers - SharePoint Fest Chicago 2013 SIA101](https://reader033.vdocuments.us/reader033/viewer/2022061119/546ac084af795920668b4bd1/html5/thumbnails/20.jpg)
20
![Page 21: Introduction to PowerShell for SharePoint Admins and Developers - SharePoint Fest Chicago 2013 SIA101](https://reader033.vdocuments.us/reader033/viewer/2022061119/546ac084af795920668b4bd1/html5/thumbnails/21.jpg)
21
The Power of Piping!
Output Of Command 1
Input of Command 2|
3
![Page 22: Introduction to PowerShell for SharePoint Admins and Developers - SharePoint Fest Chicago 2013 SIA101](https://reader033.vdocuments.us/reader033/viewer/2022061119/546ac084af795920668b4bd1/html5/thumbnails/22.jpg)
Example
![Page 23: Introduction to PowerShell for SharePoint Admins and Developers - SharePoint Fest Chicago 2013 SIA101](https://reader033.vdocuments.us/reader033/viewer/2022061119/546ac084af795920668b4bd1/html5/thumbnails/23.jpg)
Making Comparisons4Operator Meaning Operator Meaning
-eq Equals -le Less Than or Equal To
-ne Not Equals -like Wildcard Match
-gt Greater Than -notlike Not (Wildcard Match)
-ge Greater Than or Equal To
-match Reg. Exp. Match
-lt Less Than -notmatch Not (Reg. Exp. Match)
![Page 24: Introduction to PowerShell for SharePoint Admins and Developers - SharePoint Fest Chicago 2013 SIA101](https://reader033.vdocuments.us/reader033/viewer/2022061119/546ac084af795920668b4bd1/html5/thumbnails/24.jpg)
24
Example
![Page 25: Introduction to PowerShell for SharePoint Admins and Developers - SharePoint Fest Chicago 2013 SIA101](https://reader033.vdocuments.us/reader033/viewer/2022061119/546ac084af795920668b4bd1/html5/thumbnails/25.jpg)
25
Taking Control of the Flow5
• For (Init;Test;Repeat) {Commands}• for($i=1; $i -le 10; $i++) {Write-Host $i}For• Foreach (Item in Collection) {Commands}• Foreach ($web in $site.AllWebs) {$web.Title}ForEach• If (Test) {Commands} • if ($web.Title –ne “”) {Write-Host $web.Title}
If• While (Condition){Commands}• while($val -ne 3){$val++; Write-Host $val}While
![Page 26: Introduction to PowerShell for SharePoint Admins and Developers - SharePoint Fest Chicago 2013 SIA101](https://reader033.vdocuments.us/reader033/viewer/2022061119/546ac084af795920668b4bd1/html5/thumbnails/26.jpg)
Example
![Page 27: Introduction to PowerShell for SharePoint Admins and Developers - SharePoint Fest Chicago 2013 SIA101](https://reader033.vdocuments.us/reader033/viewer/2022061119/546ac084af795920668b4bd1/html5/thumbnails/27.jpg)
27
Where-Object6
•Where {<Test>}Syntax
• V1&2:Dir | Where {$_.Name –like
“B*”}• V3:Dir | where Name –like B*
Example
![Page 28: Introduction to PowerShell for SharePoint Admins and Developers - SharePoint Fest Chicago 2013 SIA101](https://reader033.vdocuments.us/reader033/viewer/2022061119/546ac084af795920668b4bd1/html5/thumbnails/28.jpg)
28
Using the SharePoint API
• Getting an SPSite1• Manipulating It2• Cleaning Up3
![Page 29: Introduction to PowerShell for SharePoint Admins and Developers - SharePoint Fest Chicago 2013 SIA101](https://reader033.vdocuments.us/reader033/viewer/2022061119/546ac084af795920668b4bd1/html5/thumbnails/29.jpg)
29
Highlights from the SharePoint Object Model
SPField
SPListItem
SPList
SPWeb
SPWebApplication
SPFarm
SPSite
![Page 30: Introduction to PowerShell for SharePoint Admins and Developers - SharePoint Fest Chicago 2013 SIA101](https://reader033.vdocuments.us/reader033/viewer/2022061119/546ac084af795920668b4bd1/html5/thumbnails/30.jpg)
30
Loading SharePoint Cmdlets
Even in MOSS 2007:[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
Loading SharePoint DLLs
C:\...\14 or 15\CONFIG\POWERSHELL\Registration\
SharePoint.ps1
![Page 31: Introduction to PowerShell for SharePoint Admins and Developers - SharePoint Fest Chicago 2013 SIA101](https://reader033.vdocuments.us/reader033/viewer/2022061119/546ac084af795920668b4bd1/html5/thumbnails/31.jpg)
31
A Word About Memory Management
SPWeb SPSite
Inline In Script
Dispose
![Page 32: Introduction to PowerShell for SharePoint Admins and Developers - SharePoint Fest Chicago 2013 SIA101](https://reader033.vdocuments.us/reader033/viewer/2022061119/546ac084af795920668b4bd1/html5/thumbnails/32.jpg)
32
![Page 33: Introduction to PowerShell for SharePoint Admins and Developers - SharePoint Fest Chicago 2013 SIA101](https://reader033.vdocuments.us/reader033/viewer/2022061119/546ac084af795920668b4bd1/html5/thumbnails/33.jpg)
33
Chapter 3
REAL WORLD EXAMPLES
![Page 34: Introduction to PowerShell for SharePoint Admins and Developers - SharePoint Fest Chicago 2013 SIA101](https://reader033.vdocuments.us/reader033/viewer/2022061119/546ac084af795920668b4bd1/html5/thumbnails/34.jpg)
34
Real World Examples
Check the Farm VersionCheck Versioning on all document LibrariesCreate List ItemsExport Web App Properties to a fileBulk Site Creation
![Page 35: Introduction to PowerShell for SharePoint Admins and Developers - SharePoint Fest Chicago 2013 SIA101](https://reader033.vdocuments.us/reader033/viewer/2022061119/546ac084af795920668b4bd1/html5/thumbnails/35.jpg)
35
What’s your SP2010 Version?
PS C:\Users\Administrator> $(get-SPFarm).BuildVersion
Major Minor Build Revision----- ----- ----- --------14 0 6109 5002
![Page 36: Introduction to PowerShell for SharePoint Admins and Developers - SharePoint Fest Chicago 2013 SIA101](https://reader033.vdocuments.us/reader033/viewer/2022061119/546ac084af795920668b4bd1/html5/thumbnails/36.jpg)
36
Get a Site and Explore it!
$site = get-spsite http://server/path
THEN$site
![Page 37: Introduction to PowerShell for SharePoint Admins and Developers - SharePoint Fest Chicago 2013 SIA101](https://reader033.vdocuments.us/reader033/viewer/2022061119/546ac084af795920668b4bd1/html5/thumbnails/37.jpg)
37
![Page 38: Introduction to PowerShell for SharePoint Admins and Developers - SharePoint Fest Chicago 2013 SIA101](https://reader033.vdocuments.us/reader033/viewer/2022061119/546ac084af795920668b4bd1/html5/thumbnails/38.jpg)
38
Check Doc Lib Versioning Settingsfunction global:show-all-doclibs ($web){$web.Lists | where-object {($_.Hidden -ne
$true) -and ($_.BaseType -eq "DocumentLibrary")} }
function global:show-all-doclib-versettings ($web)
{show-all-doclibs ($web) |select-object -property Title, EnableVersioning, MajorVersionLimit, EnableMinorVersions,MajorWithMinorVersionsLimit,forceCheckout}
$site = get-spsite “http://server/path”
show-all-doclib-versettings $site.RootWeb
![Page 39: Introduction to PowerShell for SharePoint Admins and Developers - SharePoint Fest Chicago 2013 SIA101](https://reader033.vdocuments.us/reader033/viewer/2022061119/546ac084af795920668b4bd1/html5/thumbnails/39.jpg)
39
![Page 40: Introduction to PowerShell for SharePoint Admins and Developers - SharePoint Fest Chicago 2013 SIA101](https://reader033.vdocuments.us/reader033/viewer/2022061119/546ac084af795920668b4bd1/html5/thumbnails/40.jpg)
40
Practical Uses• Bulk Create Sites1• List Item CRUD2• Create data for test cases3• Associate Workflows with a List4• Work across site collections5
• Deployment Scripting6• Identify files that won’t upload7
![Page 41: Introduction to PowerShell for SharePoint Admins and Developers - SharePoint Fest Chicago 2013 SIA101](https://reader033.vdocuments.us/reader033/viewer/2022061119/546ac084af795920668b4bd1/html5/thumbnails/41.jpg)
41
More Practical Uses• Sync Wep App Properties8• Install SharePoint9• Repeatably Manage Content10• Update Field Definitions11• Edit MP3 Metadata, Make Flashcards12
![Page 42: Introduction to PowerShell for SharePoint Admins and Developers - SharePoint Fest Chicago 2013 SIA101](https://reader033.vdocuments.us/reader033/viewer/2022061119/546ac084af795920668b4bd1/html5/thumbnails/42.jpg)
42
What’s your SharePoint Version?
PS C:\Users\Administrator> $(get-SPFarm).BuildVersion
Major Minor Build Revision----- ----- ----- --------14 0 6109 5002
![Page 43: Introduction to PowerShell for SharePoint Admins and Developers - SharePoint Fest Chicago 2013 SIA101](https://reader033.vdocuments.us/reader033/viewer/2022061119/546ac084af795920668b4bd1/html5/thumbnails/43.jpg)
43
Create a List Item
![Page 44: Introduction to PowerShell for SharePoint Admins and Developers - SharePoint Fest Chicago 2013 SIA101](https://reader033.vdocuments.us/reader033/viewer/2022061119/546ac084af795920668b4bd1/html5/thumbnails/44.jpg)
44
Audio Alerts
Stick this at the end of your long running script:
$Voice = new-object -com SAPI.SpVoice $Voice.Speak(“Deployment is done!")
![Page 45: Introduction to PowerShell for SharePoint Admins and Developers - SharePoint Fest Chicago 2013 SIA101](https://reader033.vdocuments.us/reader033/viewer/2022061119/546ac084af795920668b4bd1/html5/thumbnails/45.jpg)
45
Executing Scripts
.\filename.ps1
Set-ExecutionPolicy Unrestricted
![Page 46: Introduction to PowerShell for SharePoint Admins and Developers - SharePoint Fest Chicago 2013 SIA101](https://reader033.vdocuments.us/reader033/viewer/2022061119/546ac084af795920668b4bd1/html5/thumbnails/46.jpg)
46
Bulk Site Creation
Site Definitions in V. StudioNot an answer by themselvesDefine site contentIntended for reuse
Mismatch to one time needCAML and PITAHarder: Making it data drivenChange Site Def -> Recreate Site
PowerShell & Excel & UI
Well suited for one time “blow in’s”Define the site template in the UI or use standardSave as a template
Even pub sites - sometimesPowerShell has easy loopsData driven from a CSVChanges -> Mod Scripts
![Page 47: Introduction to PowerShell for SharePoint Admins and Developers - SharePoint Fest Chicago 2013 SIA101](https://reader033.vdocuments.us/reader033/viewer/2022061119/546ac084af795920668b4bd1/html5/thumbnails/47.jpg)
47
The PowerShell Solution
Read the list of sites from CSVLoop:
Create SiteConfigure Site
Turn on FeaturesSet Master Pages, Welcome PageHide Libraries, set versioningAdjust Navigation
Add Lists, Libraries, Pages, Web parts, etcLoop again & again if needed – iterative!
![Page 48: Introduction to PowerShell for SharePoint Admins and Developers - SharePoint Fest Chicago 2013 SIA101](https://reader033.vdocuments.us/reader033/viewer/2022061119/546ac084af795920668b4bd1/html5/thumbnails/48.jpg)
48
Chapter 4
MORE RESOURCES
![Page 49: Introduction to PowerShell for SharePoint Admins and Developers - SharePoint Fest Chicago 2013 SIA101](https://reader033.vdocuments.us/reader033/viewer/2022061119/546ac084af795920668b4bd1/html5/thumbnails/49.jpg)
Resources
Books & Blogs
People & Places
![Page 51: Introduction to PowerShell for SharePoint Admins and Developers - SharePoint Fest Chicago 2013 SIA101](https://reader033.vdocuments.us/reader033/viewer/2022061119/546ac084af795920668b4bd1/html5/thumbnails/51.jpg)
51
![Page 52: Introduction to PowerShell for SharePoint Admins and Developers - SharePoint Fest Chicago 2013 SIA101](https://reader033.vdocuments.us/reader033/viewer/2022061119/546ac084af795920668b4bd1/html5/thumbnails/52.jpg)
52
![Page 53: Introduction to PowerShell for SharePoint Admins and Developers - SharePoint Fest Chicago 2013 SIA101](https://reader033.vdocuments.us/reader033/viewer/2022061119/546ac084af795920668b4bd1/html5/thumbnails/53.jpg)
53
![Page 54: Introduction to PowerShell for SharePoint Admins and Developers - SharePoint Fest Chicago 2013 SIA101](https://reader033.vdocuments.us/reader033/viewer/2022061119/546ac084af795920668b4bd1/html5/thumbnails/54.jpg)
54
![Page 55: Introduction to PowerShell for SharePoint Admins and Developers - SharePoint Fest Chicago 2013 SIA101](https://reader033.vdocuments.us/reader033/viewer/2022061119/546ac084af795920668b4bd1/html5/thumbnails/55.jpg)
55
![Page 56: Introduction to PowerShell for SharePoint Admins and Developers - SharePoint Fest Chicago 2013 SIA101](https://reader033.vdocuments.us/reader033/viewer/2022061119/546ac084af795920668b4bd1/html5/thumbnails/56.jpg)
56
JEFF HICKS
![Page 57: Introduction to PowerShell for SharePoint Admins and Developers - SharePoint Fest Chicago 2013 SIA101](https://reader033.vdocuments.us/reader033/viewer/2022061119/546ac084af795920668b4bd1/html5/thumbnails/57.jpg)
57
Resources SummaryMSFT
PowerShell Product Team Blog Script Center
CommunityVarious BooksCodePlex: PSBBs (mine), CodePlex:SPInstaller Blog.BlumenthalIT.NetSharePointJack.comJeff Hicks , Gary LaPointe, Raymond Mitchell, Todd Klindt, POSHCODE.ORG, get-spscripts.com SPYam
![Page 58: Introduction to PowerShell for SharePoint Admins and Developers - SharePoint Fest Chicago 2013 SIA101](https://reader033.vdocuments.us/reader033/viewer/2022061119/546ac084af795920668b4bd1/html5/thumbnails/58.jpg)
58
Script something today!
It’s Easy to Get Started!
Learn & Use the PowerShell Syntax
More Resources
In Review…
![Page 59: Introduction to PowerShell for SharePoint Admins and Developers - SharePoint Fest Chicago 2013 SIA101](https://reader033.vdocuments.us/reader033/viewer/2022061119/546ac084af795920668b4bd1/html5/thumbnails/59.jpg)
59
Questions& Raffle
• Michael BlumenthalSharePoint ArchitectPSC Group, LLC
• [email protected]• psclistens.com• www.cspug.org• Twitter: @MichaelBL• SPYam
Thank you for your time today.