Presentation is loading. Please wait.

Presentation is loading. Please wait.

PowerShell for SharePoint Developers and Administrators Michael Blumenthal Magenic Technologies

Similar presentations


Presentation on theme: "PowerShell for SharePoint Developers and Administrators Michael Blumenthal Magenic Technologies"— Presentation transcript:

1 PowerShell for SharePoint Developers and Administrators Michael Blumenthal Magenic Technologies MichaelBl@Magenic.com

2 2 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

3 3 No Compiling! No Packaging! Just Code & Go! Why PowerShell?

4 4 PowerShell puts the SharePoint Engine at your fingertips! It’s Easy to Get Started! 1 Learn the PowerShell Syntax 2 Real World Examples 3 More Resources 4 Demo! 5

5 5 Chapter 1

6 Getting Started with PowerShell Windows Server 2003 Download Windows Server 2008 Install Server2008 R2, 2012, Win8 Run (Add ISE)

7 7

8 8 POSH vs the SP2010 Mgmt Shell

9 9

10 10 PowerShell V3 ISE

11 11 Chapter 2

12 Learn to use PowerShell with SharePoint! Symbols & Keywords Using the SharePoint API Creating and Running Scripts

13 13 Symbols, Keywords, and Syntax! Oh My! Variables 1 Commands 2 Piping 3 Comparisons 4 Flow Control 5 Filtering 6

14 14 Punctuation Pronunciation SymbolCalledSymbolCalled $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$#|

15 15 Variables begin with a $ Case Insensitive, Dynamic typing $foo$true, $false, $profile$foo = “Hello, World” 1

16 16

17 17 Commands are called cmdlets. Verb-Noun Built-in, Extensible Get-Help & Help Get-Member 2

18 18

19 19 The Power of Piping! Output Of Command 1 Input of Command 2 3

20 Example

21 Making Comparisons 4 OperatorMeaningOperatorMeaning -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)

22 22 Taking Control of the Flow 5 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

23 Example

24 24 Where-Object 6 Where { } Syntax V1&2:Dir | Where {$_.Name –like “B*”} V3:Dir | where Name –like B* Example

25 25 Using the SharePoint API Getting an SPSite 1 Manipulating It 2 Cleaning Up 3

26 26 Highlights from the SharePoint Object Model SPField SPListItem SPList SPWeb SPWebApplication SPFarm

27 27 Loading SharePoint 2010 Cmdlets [void][System.Reflection.Assembly]:: LoadWithPartialName ("Microsoft.SharePoint") Loading SharePoint DLLs C:\...\14\CONFIG\POWERSHELL\ Registration\SharePoint.ps1

28 28 Get a Site and Explore it! $site = get-spsite http://server/path THEN $site

29 29

30 30 Create a List Item

31 31 Practical Uses Bulk Create Sites 1 List Item CRUD 2 Create data for test cases 3 Associate Workflows with a List 4 Work across site collections 5 Deployment Scripting 6 Identify files that won’t upload 7

32 32 More Practical Uses Sync Wep App Properties 8 Install SharePoint 9 Repeatably Manage Content 10 Update Field Definitions 11 Edit MP3 Metadata, Make Flashcards 12

33 33 A Word About Memory Management SPWebSPSite InlineIn Script

34 34

35 35 Executing Scripts.\filename.ps1 Set-ExecutionPolicy Unrestricted

36 36 Chapter 3

37 37 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

38 38 What’s your SP2010 Version? PS C:\Users\Administrator> $(get- SPFarm).BuildVersion Major Minor Build Revision ----- ----- ----- -------- 14 0 6109 5002

39 39 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

40 40

41 41

42 42 Bulk Site Creation Site Definitions in V. Studio 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 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

43 43 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!

44 44 Audio Alerts Stick this at the end of your long running script: $Voice = new-object -com SAPI.SpVoice $Voice.Speak(“Deployment is done!")

45 45 Chapter 3.1

46 46 Best Practices Follow the Verb-Noun pattern 1 Comment Your Functions 2 Use Source Control 3 Write your scripts as functions that announce themselves Make accidentals runs harmless 4

47 47

48 48 Chapter 4

49 Resources SharePoint + Reflector / Decompiler Microsoft Resources 3 rd Party Resources

50 50 Use a Decompiler to see MSFT’s Code! OR ILSpy.net dotPeek (jetbrains) justDecompile (Telerik) Reflector(RedGate) Others…

51 51

52 52

53 53

54 54

55 55

56 56

57 57

58 58 Resources Summary MSFT Reverse Engineering SharePoint Pages Bruce Payette’s BookBruce Payette’s Book v2 PowerShell Product Team Blog Community CodePlex: PSBBs (mine), CodePlex:SPInstaller My Blog at BlumenthalIT.Net Jeff HicksJeff Hicks, Gary LaPointe, Raymond Mitchell, Todd Klindt POSHCODE.ORGPOSHCODE.ORG, ScriptCenter

59 59 PowerShell puts the SharePoint API at your fingertips! It’s Easy to Get Started! Learn & Use the PowerShell Syntax More Resources In Review…

60 60 Chapter 5 See the power of PowerShell + SharePoint!

61 61 Contact Me! Blog about SharePoint at http://blog. BlumenthalIT.net http://blog. BlumenthalIT.net Twitter: @MichaelBL MichaelBL@magenic.comMichaelBL@magenic.com & http://www.Magenic.com http://www.Magenic.com Yammer / SPYam

62 62 September Community Events CSPUG Meeting / SPFest Speaker Panel 9/25 SPFest – 25-27 SP Saturday 9/29 – maybe?

63 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!


Download ppt "PowerShell for SharePoint Developers and Administrators Michael Blumenthal Magenic Technologies"

Similar presentations


Ads by Google