powershell for sharepoint developers and administrators
DESCRIPTION
PowerShell for SharePoint Developers and Administrators . Michael Blumenthal Magenic Technologies [email protected]. Who is Michael Blumenthal?. Associate Principal Consultant at Magenic 17 years in IT Consulting 9 years working with SharePoint (2003,2007,2010, 2013) - PowerPoint PPT PresentationTRANSCRIPT
![Page 1: PowerShell for SharePoint Developers and Administrators](https://reader035.vdocuments.site/reader035/viewer/2022062501/5681634b550346895dd3dd21/html5/thumbnails/1.jpg)
PowerShell for SharePoint Developers and
Administrators
Michael BlumenthalMagenic Technologies
![Page 2: PowerShell for SharePoint Developers and Administrators](https://reader035.vdocuments.site/reader035/viewer/2022062501/5681634b550346895dd3dd21/html5/thumbnails/2.jpg)
2
Who is Michael Blumenthal?
Associate Principal Consultantat Magenic
17 years in IT Consulting
9 years working with SharePoint (2003,2007,2010, 2013)
3x INETA Champ, CSPUG Co-Leader, SP Speaker
![Page 3: PowerShell for SharePoint Developers and Administrators](https://reader035.vdocuments.site/reader035/viewer/2022062501/5681634b550346895dd3dd21/html5/thumbnails/3.jpg)
3
No Compiling!
No Packaging!
Just Code & Go!
Why PowerShell?
![Page 4: PowerShell for SharePoint Developers and Administrators](https://reader035.vdocuments.site/reader035/viewer/2022062501/5681634b550346895dd3dd21/html5/thumbnails/4.jpg)
4
PowerShell puts the SharePoint Engine at your fingertips!
• It’s Easy to Get Started!1• Learn the PowerShell Syntax2• Real World Examples3• More Resources4• Demo!5
![Page 5: PowerShell for SharePoint Developers and Administrators](https://reader035.vdocuments.site/reader035/viewer/2022062501/5681634b550346895dd3dd21/html5/thumbnails/5.jpg)
5
Chapter 1
IT’S EASY TO GET STARTED!
![Page 6: PowerShell for SharePoint Developers and Administrators](https://reader035.vdocuments.site/reader035/viewer/2022062501/5681634b550346895dd3dd21/html5/thumbnails/6.jpg)
Getting Started with PowerShell
Windows Server 2003• Download
Windows Server 2008• Install
Server2008 R2, 2012, Win8• Run (Add ISE)
![Page 7: PowerShell for SharePoint Developers and Administrators](https://reader035.vdocuments.site/reader035/viewer/2022062501/5681634b550346895dd3dd21/html5/thumbnails/7.jpg)
7
![Page 8: PowerShell for SharePoint Developers and Administrators](https://reader035.vdocuments.site/reader035/viewer/2022062501/5681634b550346895dd3dd21/html5/thumbnails/8.jpg)
8
POSH vs the SP2010 Mgmt Shell
![Page 9: PowerShell for SharePoint Developers and Administrators](https://reader035.vdocuments.site/reader035/viewer/2022062501/5681634b550346895dd3dd21/html5/thumbnails/9.jpg)
9
V2
![Page 10: PowerShell for SharePoint Developers and Administrators](https://reader035.vdocuments.site/reader035/viewer/2022062501/5681634b550346895dd3dd21/html5/thumbnails/10.jpg)
10
PowerShell V3 ISE
![Page 11: PowerShell for SharePoint Developers and Administrators](https://reader035.vdocuments.site/reader035/viewer/2022062501/5681634b550346895dd3dd21/html5/thumbnails/11.jpg)
11
Chapter 2
LEARN THE POWERSHELL SYNTAX!
![Page 12: PowerShell for SharePoint Developers and Administrators](https://reader035.vdocuments.site/reader035/viewer/2022062501/5681634b550346895dd3dd21/html5/thumbnails/12.jpg)
Learn to use PowerShell with SharePoint!
Symbols & Keywords
Using the SharePoint API
Creating and Running Scripts
![Page 13: PowerShell for SharePoint Developers and Administrators](https://reader035.vdocuments.site/reader035/viewer/2022062501/5681634b550346895dd3dd21/html5/thumbnails/13.jpg)
13
Symbols, Keywords, and Syntax! Oh My!
• Variables1• Commands2• Piping3• Comparisons4• Flow Control5• Filtering6
![Page 14: PowerShell for SharePoint Developers and Administrators](https://reader035.vdocuments.site/reader035/viewer/2022062501/5681634b550346895dd3dd21/html5/thumbnails/14.jpg)
14
Punctuation PronunciationSymbol Called Symbol Called$ Dollar sign, money _ Underscore# Pound, hash [ ] 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 15: PowerShell for SharePoint Developers and Administrators](https://reader035.vdocuments.site/reader035/viewer/2022062501/5681634b550346895dd3dd21/html5/thumbnails/15.jpg)
15
Variables begin with a $
• Case Insensitive, Dynamic typing
$foo
$true, $false, $profile
$foo = “Hello, World”
1
![Page 16: PowerShell for SharePoint Developers and Administrators](https://reader035.vdocuments.site/reader035/viewer/2022062501/5681634b550346895dd3dd21/html5/thumbnails/16.jpg)
16
![Page 17: PowerShell for SharePoint Developers and Administrators](https://reader035.vdocuments.site/reader035/viewer/2022062501/5681634b550346895dd3dd21/html5/thumbnails/17.jpg)
17
Commands are called cmdlets.Verb-Noun
Built-in, Extensible
Get-Help & Help
Get-Member
2
![Page 18: PowerShell for SharePoint Developers and Administrators](https://reader035.vdocuments.site/reader035/viewer/2022062501/5681634b550346895dd3dd21/html5/thumbnails/18.jpg)
18
![Page 19: PowerShell for SharePoint Developers and Administrators](https://reader035.vdocuments.site/reader035/viewer/2022062501/5681634b550346895dd3dd21/html5/thumbnails/19.jpg)
19
The Power of Piping!
Output Of Command
1
Input of Command
2|
3
![Page 20: PowerShell for SharePoint Developers and Administrators](https://reader035.vdocuments.site/reader035/viewer/2022062501/5681634b550346895dd3dd21/html5/thumbnails/20.jpg)
Example
![Page 21: PowerShell for SharePoint Developers and Administrators](https://reader035.vdocuments.site/reader035/viewer/2022062501/5681634b550346895dd3dd21/html5/thumbnails/21.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 22: PowerShell for SharePoint Developers and Administrators](https://reader035.vdocuments.site/reader035/viewer/2022062501/5681634b550346895dd3dd21/html5/thumbnails/22.jpg)
22
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 23: PowerShell for SharePoint Developers and Administrators](https://reader035.vdocuments.site/reader035/viewer/2022062501/5681634b550346895dd3dd21/html5/thumbnails/23.jpg)
Example
![Page 24: PowerShell for SharePoint Developers and Administrators](https://reader035.vdocuments.site/reader035/viewer/2022062501/5681634b550346895dd3dd21/html5/thumbnails/24.jpg)
24
Where-Object6
•Where {<Test>}Syntax
• V1&2:Dir | Where {$_.Name –like
“B*”}• V3:Dir | where Name –like B*
Example
![Page 25: PowerShell for SharePoint Developers and Administrators](https://reader035.vdocuments.site/reader035/viewer/2022062501/5681634b550346895dd3dd21/html5/thumbnails/25.jpg)
25
Using the SharePoint API
• Getting an SPSite1• Manipulating It2• Cleaning Up3
![Page 26: PowerShell for SharePoint Developers and Administrators](https://reader035.vdocuments.site/reader035/viewer/2022062501/5681634b550346895dd3dd21/html5/thumbnails/26.jpg)
26
Highlights from the SharePoint Object Model
SPField
SPListItem
SPList
SPWeb
SPWebApplication
SPFarm
SPSite
![Page 27: PowerShell for SharePoint Developers and Administrators](https://reader035.vdocuments.site/reader035/viewer/2022062501/5681634b550346895dd3dd21/html5/thumbnails/27.jpg)
27
Loading SharePoint 2010 Cmdlets
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
Loading SharePoint DLLs
C:\...\14\CONFIG\POWERSHELL\Registration\
SharePoint.ps1
![Page 28: PowerShell for SharePoint Developers and Administrators](https://reader035.vdocuments.site/reader035/viewer/2022062501/5681634b550346895dd3dd21/html5/thumbnails/28.jpg)
28
Get a Site and Explore it!
$site = get-spsite http://server/path
THEN$site
![Page 29: PowerShell for SharePoint Developers and Administrators](https://reader035.vdocuments.site/reader035/viewer/2022062501/5681634b550346895dd3dd21/html5/thumbnails/29.jpg)
29
![Page 30: PowerShell for SharePoint Developers and Administrators](https://reader035.vdocuments.site/reader035/viewer/2022062501/5681634b550346895dd3dd21/html5/thumbnails/30.jpg)
30
Create a List Item
![Page 31: PowerShell for SharePoint Developers and Administrators](https://reader035.vdocuments.site/reader035/viewer/2022062501/5681634b550346895dd3dd21/html5/thumbnails/31.jpg)
31
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 32: PowerShell for SharePoint Developers and Administrators](https://reader035.vdocuments.site/reader035/viewer/2022062501/5681634b550346895dd3dd21/html5/thumbnails/32.jpg)
32
More Practical Uses• Sync Wep App Properties8• Install SharePoint9• Repeatably Manage Content10• Update Field Definitions11• Edit MP3 Metadata, Make Flashcards12
![Page 33: PowerShell for SharePoint Developers and Administrators](https://reader035.vdocuments.site/reader035/viewer/2022062501/5681634b550346895dd3dd21/html5/thumbnails/33.jpg)
33
A Word About Memory Management
SPWeb SPSite
Inline In Script
Dispose
![Page 34: PowerShell for SharePoint Developers and Administrators](https://reader035.vdocuments.site/reader035/viewer/2022062501/5681634b550346895dd3dd21/html5/thumbnails/34.jpg)
34
![Page 35: PowerShell for SharePoint Developers and Administrators](https://reader035.vdocuments.site/reader035/viewer/2022062501/5681634b550346895dd3dd21/html5/thumbnails/35.jpg)
35
Executing Scripts
.\filename.ps1
Set-ExecutionPolicy Unrestricted
![Page 36: PowerShell for SharePoint Developers and Administrators](https://reader035.vdocuments.site/reader035/viewer/2022062501/5681634b550346895dd3dd21/html5/thumbnails/36.jpg)
36
Chapter 3
REAL WORLD EXAMPLES
![Page 37: PowerShell for SharePoint Developers and Administrators](https://reader035.vdocuments.site/reader035/viewer/2022062501/5681634b550346895dd3dd21/html5/thumbnails/37.jpg)
37
Real World Examples
Check the Farm VersionCheck Versioning on all document LibrariesCreate List ItemsBulk Site CreationPost Deployment Build Scripts with Audio Alerts
![Page 38: PowerShell for SharePoint Developers and Administrators](https://reader035.vdocuments.site/reader035/viewer/2022062501/5681634b550346895dd3dd21/html5/thumbnails/38.jpg)
38
What’s your SP2010 Version?
PS C:\Users\Administrator> $(get-SPFarm).BuildVersion
Major Minor Build Revision----- ----- ----- --------14 0 6109 5002
![Page 39: PowerShell for SharePoint Developers and Administrators](https://reader035.vdocuments.site/reader035/viewer/2022062501/5681634b550346895dd3dd21/html5/thumbnails/39.jpg)
39
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 40: PowerShell for SharePoint Developers and Administrators](https://reader035.vdocuments.site/reader035/viewer/2022062501/5681634b550346895dd3dd21/html5/thumbnails/40.jpg)
40
![Page 41: PowerShell for SharePoint Developers and Administrators](https://reader035.vdocuments.site/reader035/viewer/2022062501/5681634b550346895dd3dd21/html5/thumbnails/41.jpg)
41
![Page 42: PowerShell for SharePoint Developers and Administrators](https://reader035.vdocuments.site/reader035/viewer/2022062501/5681634b550346895dd3dd21/html5/thumbnails/42.jpg)
42
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 sitesPowerShell has easy loopsData driven from a CSVChanges -> Mod Scripts
![Page 43: PowerShell for SharePoint Developers and Administrators](https://reader035.vdocuments.site/reader035/viewer/2022062501/5681634b550346895dd3dd21/html5/thumbnails/43.jpg)
43
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 44: PowerShell for SharePoint Developers and Administrators](https://reader035.vdocuments.site/reader035/viewer/2022062501/5681634b550346895dd3dd21/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: PowerShell for SharePoint Developers and Administrators](https://reader035.vdocuments.site/reader035/viewer/2022062501/5681634b550346895dd3dd21/html5/thumbnails/45.jpg)
45
Chapter 3.1
BEST PRACTICES
![Page 46: PowerShell for SharePoint Developers and Administrators](https://reader035.vdocuments.site/reader035/viewer/2022062501/5681634b550346895dd3dd21/html5/thumbnails/46.jpg)
46
Best Practices
• Follow the Verb-Noun pattern1• Comment Your Functions2• Use Source Control3• Write your scripts as functions that
announce themselves• Make accidentals runs harmless
4
![Page 47: PowerShell for SharePoint Developers and Administrators](https://reader035.vdocuments.site/reader035/viewer/2022062501/5681634b550346895dd3dd21/html5/thumbnails/47.jpg)
47
![Page 48: PowerShell for SharePoint Developers and Administrators](https://reader035.vdocuments.site/reader035/viewer/2022062501/5681634b550346895dd3dd21/html5/thumbnails/48.jpg)
48
Chapter 4
MORE RESOURCES
![Page 49: PowerShell for SharePoint Developers and Administrators](https://reader035.vdocuments.site/reader035/viewer/2022062501/5681634b550346895dd3dd21/html5/thumbnails/49.jpg)
Resources
SharePoint + Reflector / Decompiler
Microsoft Resources
3rd Party Resources
![Page 50: PowerShell for SharePoint Developers and Administrators](https://reader035.vdocuments.site/reader035/viewer/2022062501/5681634b550346895dd3dd21/html5/thumbnails/50.jpg)
50
Use a Decompiler to see MSFT’s Code!
OR
ILSpy.netdotPeek (jetbrains)justDecompile (Telerik)Reflector(RedGate)Others…NO
LONGER
FREE
![Page 52: PowerShell for SharePoint Developers and Administrators](https://reader035.vdocuments.site/reader035/viewer/2022062501/5681634b550346895dd3dd21/html5/thumbnails/52.jpg)
52
![Page 53: PowerShell for SharePoint Developers and Administrators](https://reader035.vdocuments.site/reader035/viewer/2022062501/5681634b550346895dd3dd21/html5/thumbnails/53.jpg)
53
![Page 54: PowerShell for SharePoint Developers and Administrators](https://reader035.vdocuments.site/reader035/viewer/2022062501/5681634b550346895dd3dd21/html5/thumbnails/54.jpg)
54
![Page 55: PowerShell for SharePoint Developers and Administrators](https://reader035.vdocuments.site/reader035/viewer/2022062501/5681634b550346895dd3dd21/html5/thumbnails/55.jpg)
55
![Page 56: PowerShell for SharePoint Developers and Administrators](https://reader035.vdocuments.site/reader035/viewer/2022062501/5681634b550346895dd3dd21/html5/thumbnails/56.jpg)
56
![Page 57: PowerShell for SharePoint Developers and Administrators](https://reader035.vdocuments.site/reader035/viewer/2022062501/5681634b550346895dd3dd21/html5/thumbnails/57.jpg)
57
JEFF HICKS
![Page 58: PowerShell for SharePoint Developers and Administrators](https://reader035.vdocuments.site/reader035/viewer/2022062501/5681634b550346895dd3dd21/html5/thumbnails/58.jpg)
58
Resources Summary
MSFTReverse Engineering SharePoint PagesBruce Payette’s Book v2PowerShell Product Team Blog
CommunityCodePlex: PSBBs (mine), CodePlex:SPInstaller My Blog at BlumenthalIT.NetJeff Hicks , Gary LaPointe, Raymond Mitchell, Todd KlindtPOSHCODE.ORG, ScriptCenter
![Page 59: PowerShell for SharePoint Developers and Administrators](https://reader035.vdocuments.site/reader035/viewer/2022062501/5681634b550346895dd3dd21/html5/thumbnails/59.jpg)
59
PowerShell puts the SharePoint API at your fingertips!
It’s Easy to Get Started!
Learn & Use the PowerShell Syntax
More Resources
In Review…
![Page 60: PowerShell for SharePoint Developers and Administrators](https://reader035.vdocuments.site/reader035/viewer/2022062501/5681634b550346895dd3dd21/html5/thumbnails/60.jpg)
60
Chapter 5
See the power of PowerShell + SharePoint!
DEMO!
![Page 61: PowerShell for SharePoint Developers and Administrators](https://reader035.vdocuments.site/reader035/viewer/2022062501/5681634b550346895dd3dd21/html5/thumbnails/61.jpg)
61
Contact Me!
Blog about SharePoint at http://blog.BlumenthalIT.net
Twitter: @MichaelBL
[email protected] & http://www.Magenic.com
Yammer / SPYam
![Page 62: PowerShell for SharePoint Developers and Administrators](https://reader035.vdocuments.site/reader035/viewer/2022062501/5681634b550346895dd3dd21/html5/thumbnails/62.jpg)
62
September Community Events
CSPUG Meeting / SPFest Speaker Panel 9/25SPFest – 25-27SP Saturday 9/29 – maybe?
![Page 63: PowerShell for SharePoint Developers and Administrators](https://reader035.vdocuments.site/reader035/viewer/2022062501/5681634b550346895dd3dd21/html5/thumbnails/63.jpg)
63
Gold
• Application Integration
• Data Platform• Digital
Marketing• Portals and
Collaboration• Software
Development• Web
Development
Silver
• Application Lifecycle Management
• Business Intelligence
• Content Management
• Mobility• Search
SDPS Program Member
Enterprise SP Development Experts
Numerous Microsoft Competencies, including:
PS: We’re hiring!