630 likes | 835 Views
PowerShell for SharePoint Developers and Administrators . Michael Blumenthal Magenic Technologies MichaelBl@Magenic.com. Who is Michael Blumenthal?. Associate Principal Consultant at Magenic 17 years in IT Consulting 9 years working with SharePoint (2003,2007,2010, 2013)
E N D
PowerShell for SharePoint Developers and Administrators Michael Blumenthal Magenic Technologies MichaelBl@Magenic.com
Who is Michael Blumenthal? • Associate Principal Consultant at Magenic • 17 years in IT Consulting • 9 years working with SharePoint (2003,2007,2010, 2013) • 3x INETA Champ, CSPUG Co-Leader, SP Speaker
Chapter 1 It’s Easy to get Started!
Chapter 2 Learn the PowerShell Syntax!
1 Variables begin with a $
The Power of Piping! • 3 |
Where-Object • 6
Loading SharePoint 2010 Cmdlets C:\...\14\CONFIG\POWERSHELL\ Registration\SharePoint.ps1 [void][System.Reflection.Assembly]:: LoadWithPartialName("Microsoft.SharePoint") Loading SharePoint DLLs
Get a Site and Explore it! $site = get-spsite http://server/path THEN $site
A Word About Memory Management Dispose
Chapter 3 Real World Examples
Real World Examples • Check the Farm Version • Check Versioning on all document Libraries • Create List Items • Bulk Site Creation • Post Deployment Build Scripts with Audio Alerts
What’s your SP2010 Version? PS C:\Users\Administrator> $(get-SPFarm).BuildVersion Major Minor Build Revision ----- ----- ----- -------- 14 0 6109 5002
Check Doc Lib Versioning Settings function 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
Bulk Site Creation Site Definitions in V. Studio PowerShell & Excel & UI Well suited for one time “blow in’s” Define the site template in the UI or use standard Save as a template Even pub sites PowerShell has easy loops Data driven from a CSV Changes -> Mod Scripts • Not an answer by themselves • Define site content • Intended for reuse • Mismatch to one time need • CAML and PITA • Harder: Making it data driven • Change Site Def -> Recreate Site
The PowerShell Solution • Read the list of sites from CSV • Loop: • Create Site • Configure Site • Turn on Features • Set Master Pages, Welcome Page • Hide Libraries, set versioning • Adjust Navigation • Add Lists, Libraries, Pages, Web parts, etc • Loop again & again if needed – iterative!
Audio Alerts • Stick this at the end of your long running script: $Voice = new-object -com SAPI.SpVoice$Voice.Speak(“Deployment is done!")
Chapter 3.1 Best Practices
Chapter 4 More Resources
Use a Decompiler to see MSFT’s Code! OR ILSpy.net dotPeek (jetbrains) justDecompile (Telerik) Reflector(RedGate) Others… No Longer Free