Introduction to PowerShell for SharePoint Admins and Developers - SharePoint Fest Chicago 2013 SIA101

  • 254 views
Uploaded on

An introduction to PowerShell v3 for SharePoint Developers and Administrators. Given at SharePoint Fest Chicago 2013, session SIA101.

An introduction to PowerShell v3 for SharePoint Developers and Administrators. Given at SharePoint Fest Chicago 2013, session SIA101.

More in: Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
    Be the first to like this
No Downloads

Views

Total Views
254
On Slideshare
0
From Embeds
0
Number of Embeds
4

Actions

Shares
Downloads
12
Comments
0
Likes
0

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide
  • Every SharePoint Developer needs this!Fast and FlexibleGreat for LastMile Problems. New MSFT std for Scripting
  • Who would like another tool in their toolbox, one that will help them with SharePoint, but also with many other things? How about the swiss army knife of tools?It will make you a better developer!
  • Who here already has installed and PowerShell? Who’s using Server 2003? 2008?Win 2003: http://www.microsoft.com/windowsserver2003/technologies/management/powershell/download.mspxWin 2008 – It’s an OS Feature – “servermanagercmd –install PowerShell”V3 is here
  • One is SharePoint aware, the other isn’t!
  • Does anyone have any other names for these?Victor Borge has his own take on these: http://www.youtube.com/watch?v=lF4qii8S3gw
  • Name that Language…Similar to @variables in SQL, apparently also Ruby, PHP.Arrays start at 0
  • Mention Aliases
  • Ask if anyone has unix scripting experience, and what they think of this.Can you imagine trying to do this in unix or vbscript?
  • Get-Help about_flow_controlMention that collections start at 0
  • Ask if anyone has unix scripting experience, and what they think of this.Can you imagine trying to do this in unix or vbscript?
  • If you are familiar with these objects, raise your hand.
  • Your mother doesn’t work here! You must clean up after yourself.
  • http://sharepoint.microsoft.com/blog/Pages/BlogPost.aspx?PageType=4&ListId={72C1C85B-1D2D-4A4A-90DE-CA74A7808184}&pID=524http://msdn.microsoft.com/en-us/library/ee557362.aspxSee Assignment collections - http://technet.microsoft.com/en-us/library/ff607664.aspx
  • Michael
  • Once used a choice column’s values instead of a CSV
  • Windows PowerShell in Action by Bruce Payette, V2Since then Hicks and Jones have written some good ones
  • http://technet.microsoft.com/en-us/scriptcenter/default
  • http://www.codeplex.com/psbb
  • Blog.blumenthalit.comBlog.blumenthalit.com/files/powershellhttp://blog.blumenthalit.com/blog/Lists/Posts/Post.aspx?ID=161, etc
  • Also:PoshCode.OrgTechNet Script Center http://www.microsoft.com/technet/scriptcenter/default.mspx MSDN SharePoint Developer Center http://msdn.microsoft.com/en-us/office/aa905503.aspx Zach Rosenfield’s Blog - http://sharepoint.microsoft.com/blogs/zach/default.aspxhttp://blog.falchionconsulting.com/http://www.powergui.org/downloads.jspahttp://thepowershellguy.com/blogs/posh/pages/powertab.aspx
  • You owe it to yourself to try out PowerShell.It will make you a better developer!

Transcript

  • 1. Introduction to PowerShell for SharePoint Developers and Administrators SIA 101 Michael Blumenthal PSC Group, LLC
  • 2. 2 Who is Michael Blumenthal? Sr. Solution Architect at PSC Group CSPUG Co-Leader INETA Champ 2010-2013 18 years in IT Consulting 10 years working with SharePoint (2003,2007,2010, 2013)
  • 3. 3 This is about you Version of SharePoint? Admin, Developer, Both, Other? PowerShell experience? SharePoint experience? Unix experience? Scripting experience?
  • 4. 4 No Compiling! No Packaging! Just Code & Go! Why PowerShell?
  • 5. 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
  • 6. 6 Chapter 1
  • 7. Getting Started with PowerShell Windows Server 2003 • Download Windows Server 2008 • Install Server2008 R2, 2012, Win8 • Run (Add ISE)
  • 8. 8
  • 9. 9
  • 10. 10
  • 11. 11 PowerShell V3 ISE
  • 12. 12 POSH vs the SharePoint Mgmt Shell
  • 13. 13 Chapter 2
  • 14. Learn to use PowerShellwith SharePoint! Symbols & Keywords Using the SharePoint API Creating and Running Scripts
  • 15. 15 Symbols, Keywords, and Syntax! Oh My! • Variables1 • Commands2 • Piping3 • Comparisons4 • Flow Control5 • Filtering6
  • 16. 16 Punctuation Pronunciation Symbol 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$#|
  • 17. 17 Variables begin with a $ • Case Insensitive, Dynamic typing $foo $true, $false, $profile, $null $foo = “Hello, World” 1
  • 18. 18
  • 19. 19 Commands are called cmdlets. Verb-Noun Built-in, Extensible Get-Help & Help Get-Member 2
  • 20. 20
  • 21. 21 The Power of Piping! Output Of Command 1 Input of Command 2 3
  • 22. Example
  • 23. Making Comparisons4 Operator 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)
  • 24. 24 Example
  • 25. 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
  • 26. Example
  • 27. 27 Where-Object6 •Where {<Test>}Syntax • V1&2:Dir | Where {$_.Name –like “B*”} • V3:Dir | where Name –like B* Example
  • 28. 28 Using the SharePoint API •Getting an SPSite1 •Manipulating It2 •Cleaning Up3
  • 29. 29 Highlights from the SharePoint Object Model SPField SPListItem SPList SPWeb SPWebApplication SPFarm
  • 30. 30 Loading SharePoint Cmdlets Even in MOSS 2007: [void][System.Reflection.Assembly]:: LoadWithPartialName("Microsoft.SharePoint") Loading SharePoint DLLs C:...14 or 15CONFIGPOWERSHELL RegistrationSharePoint.ps1
  • 31. 31 A Word About Memory Management SPWeb SPSite Inline In Script
  • 32. 32
  • 33. 33 Chapter 3
  • 34. 34 Real World Examples Check the Farm Version Check Versioning on all document Libraries Create List Items Export Web App Properties to a file Bulk Site Creation
  • 35. 35 What’s your SP2010 Version? PS C:UsersAdministrator> $(get- SPFarm).BuildVersion Major Minor Build Revision ----- ----- ----- -------- 14 0 6109 5002
  • 36. 36 Get a Site and Explore it! $site = get-spsite http://server/path THEN $site
  • 37. 37
  • 38. 38 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
  • 39. 39
  • 40. 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
  • 41. 41 More Practical Uses • Sync Wep App Properties8 • Install SharePoint9 • Repeatably Manage Content10 • Update Field Definitions11 • Edit MP3 Metadata, Make Flashcards12
  • 42. 42 What’s your SharePoint Version? PS C:UsersAdministrator> $(get- SPFarm).BuildVersion Major Minor Build Revision ----- ----- ----- -------- 14 0 6109 5002
  • 43. 43 Create a List Item
  • 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 Executing Scripts .filename.ps1 Set-ExecutionPolicy Unrestricted
  • 46. 46 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 - sometimes PowerShell has easy loops Data driven from a CSV Changes -> Mod Scripts
  • 47. 47 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!
  • 48. 48 Chapter 4
  • 49. Resources Books & Blogs People & Places
  • 50. 50
  • 51. 51
  • 52. 52
  • 53. 53
  • 54. 54
  • 55. 55
  • 56. 56
  • 57. 57 Resources Summary MSFT PowerShell Product Team Blog Script Center Community Various Books CodePlex: PSBBs (mine), CodePlex:SPInstaller Blog.BlumenthalIT.Net SharePointJack.com Jeff Hicks , Gary LaPointe, Raymond Mitchell, Todd Klindt, POSHCODE.ORG, get-spscripts.com SPYam
  • 58. 58 Script something today! It’s Easy to Get Started! Learn & Use the PowerShell Syntax More Resources In Review…
  • 59. 59 Questions & Raffle • Michael Blumenthal SharePoint Architect PSC Group, LLC • MBlumenthal@psclistens.com • psclistens.com • www.cspug.org • Twitter: @MichaelBL • SPYam Thank you for your time today.