Introduction to PowerShell - Be a PowerShell Hero - SPFest workshop

  • 274 views
Uploaded on

The slides from Michael Blumenthal's and Jack Fruh's "Be a Hero with PowerShell" workshop at SharePoint fest, a comprehensive introduction to using PowerShell with SharePoint.

The slides from Michael Blumenthal's and Jack Fruh's "Be a Hero with PowerShell" workshop at SharePoint fest, a comprehensive introduction to using PowerShell with SharePoint.

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
274
On Slideshare
0
From Embeds
0
Number of Embeds
2

Actions

Shares
Downloads
22
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
  • Anyone here not done SharePoint development?What kind of development have you done?Who has worked with PowerShell already? Used for what? Your name?Who has worked with other scripting languages?
  • 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
  • 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!
  • It’s got a Watch Window
  • http://technet.microsoft.com/en-us/magazine/ff458353.aspx
  • Try to use an existing verb. You can make your own Noun Prefix if you want.
  • about_comment_based_help
  • Jack
  • Michael
  • Once used a choice column’s values instead of a CSV
  • Michael
  • Jack
  • 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 Michael Blumenthal & Jack Fruh
  • 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 Who is Jack Fruh? SharePoint Administrator Fortune 500 Company Big on community SPS Chicago Suburbs Co- Leader SharePointJack.com SPYam SharePoint-Community.org
  • 4. 4 This is about you Version of SharePoint? Admin, Developer, Both, Other? PowerShell experience? SharePoint experience?
  • 5. 5 No Compiling! No Packaging! Just Code & Go! Why PowerShell?
  • 6. 6 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
  • 7. 7 Chapter 1
  • 8. Getting Started with PowerShell Windows Server 2003 • Download Windows Server 2008 • Install Server2008 R2, 2012, Win8 • Run (Add ISE)
  • 9. 9
  • 10. 10
  • 11. 11
  • 12. 12 PowerShell V3 ISE
  • 13. 13 POSH vs the SharePoint Mgmt Shell
  • 14. 14 Chapter 2
  • 15. Learn to use PowerShellwith SharePoint! Symbols & Keywords Using the SharePoint API Creating and Running Scripts
  • 16. 16 Symbols, Keywords, and Syntax! Oh My! • Variables1 • Commands2 • Piping3 • Comparisons4 • Flow Control5 • Filtering6
  • 17. 17 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$#|
  • 18. 18 Variables begin with a $ • Case Insensitive, Dynamic typing $foo $true, $false, $profile, $null $foo = “Hello, World” 1
  • 19. 19
  • 20. 20 Commands are called cmdlets. Verb-Noun Built-in, Extensible Get-Help & Help Get-Member 2
  • 21. 21
  • 22. 22 The Power of Piping! Output Of Command 1 Input of Command 2 3
  • 23. Example
  • 24. 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)
  • 25. 25 Example
  • 26. 26 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
  • 27. Example
  • 28. 28 Where-Object6 •Where {<Test>}Syntax • V1&2:Dir | Where {$_.Name –like “B*”} • V3:Dir | where Name –like B* Example
  • 29. DEMO Directory Sorting
  • 30. 30 Using the SharePoint API •Getting an SPSite1 •Manipulating It2 •Cleaning Up3
  • 31. 31 Highlights from the SharePoint Object Model SPField SPListItem SPList SPWeb SPWebApplication SPFarm
  • 32. 32 Loading SharePoint Cmdlets Even in MOSS 2007: [void][System.Reflection.Assembly]:: LoadWithPartialName("Microsoft.SharePoint") Loading SharePoint DLLs C:...14 or 15CONFIGPOWERSHELL RegistrationSharePoint.ps1
  • 33. 33 DEMO: ISE needs to load snapin
  • 34. 34 Get a Site and Explore it! $site = get-spsite http://server/path THEN $site
  • 35. 35
  • 36. DEMO Web, Site, Lists
  • 37. 37 A Word About Memory Management SPWeb SPSite Inline In Script
  • 38. 38
  • 39. 39
  • 40. 40 Chapter 3
  • 41. 41 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
  • 42. 42 More Practical Uses • Sync Wep App Properties8 • Install SharePoint9 • Repeatably Manage Content10 • Update Field Definitions11 • Edit MP3 Metadata, Make Flashcards12
  • 43. 43 Real World Examples Check the Farm Version Create List Items Bulk Site Creation Post Deployment Build Scripts with Audio Alerts Document Versioning Settings (later)
  • 44. 44 What’s your SharePoint Version? PS C:UsersAdministrator> $(get- SPFarm).BuildVersion Major Minor Build Revision ----- ----- ----- -------- 14 0 6109 5002
  • 45. DEMO Farm & Build Ver
  • 46. 46 Create a List Item
  • 47. DEMO Create New Item
  • 48. 48 Audio Alerts Stick this at the end of your long running script: $Voice = new-object -com SAPI.SpVoice $Voice.Speak(“Deployment is done!")
  • 49. 49 Email Alerts Send-MailMessage [-To] <string[]> [- Subject] <string> [[-Body] <string>] [[- SmtpServer] <string>] -From <string> [- Attachments <string[]>] [-Bcc <string[]>] [-BodyAsHtml] [-Encoding <Encoding>] [-Cc <string[]>] [- DeliveryNotificationOption <DeliveryNotificationOptions>] [- Priority <MailPriority>] [-Credential <pscredential>] [-UseSsl] [-Port <int>] [<CommonParameters>]
  • 50. 50 Executing Scripts .filename.ps1 Set-ExecutionPolicy Unrestricted
  • 51. DEMO Run a Script – See Exec Pol
  • 52. 52 Chapter 4
  • 53. 53 Tools and Best Practices •Tools1 •Best Practices2 •Resources3
  • 54. Tools ISE •Add Windows Feature PowerShell Plus - Idera •SP2010 focused PowerGui •Pro version Too PowerShell Studio - Sapien •Not Free Visual Studio 2012
  • 55. 55 ISE, ISE Baby Microsoft’s Available Since POSH V2 • SP2010 -> POSH 2; SP2013 -> POSH 3 OS Feature
  • 56. 56 You might have to add the ISE
  • 57. 57
  • 58. 58 PowerShell V3 ISE - for SP2013
  • 59. 59 POSH vs the SharePoint Mgmt Shell POSH + SnapIn = SharePoint Management Shell
  • 60. 60 Where is it?
  • 61. 61
  • 62. 62 Demo – ISE Debugging
  • 63. 63 Visual Studio 2012 Update 3 Integration with TFS For SharePoint developers, tool of choice Add-ons available
  • 64. 64
  • 65. 65
  • 66. 66
  • 67. 67 PowerGUI Created for POSH v1 originally Free & large community support Lots of Add-ons • SCCS in Pro
  • 68. 68
  • 69. 69 PowerGUI screen shot
  • 70. 70 Idera’s PowerShell Plus Free with ads for Idera’s other products Includes support for SP2010, but not 2013 Framework Dependecy…. Lots of features…. Bloated Overkill?
  • 71. 71
  • 72. 72 Sapien’s PowerShell Studio Trial requires special trial license in a VM Does create a POSH Library
  • 73. 73
  • 74. 74 Sapien Bonus
  • 75. 75 Conclusion on POSH IDEs
  • 76. 76
  • 77. 77 Best Practices • Follow the Verb-Noun pattern1 • Comment Your Functions2 • Write your scripts as functions that announce themselves •Make accidentals runs harmless 3 • Use Source Control4
  • 78. 78 Verb-Noun = Action-Thing Add Backup Clear Connect Convert Copy Disable Disconnect Dismount Enable Etc… SPAppDeniedEndpoint SPClaimTypeMapping SPDiagnosticsPerformanceCo unter SPDistributedCacheServiceIns tance SPEduClassMember SPEduUser SPInfoPathUserAgent SPPluggableSecurityTrimmer SPProfileLeader SPProfileSyncConnection Etc… 42 verbs combined with 347 nouns to give us 799 cmdlets
  • 79. 79 Comment your functions <# .SYNOPSIS –a brief explanation of what the script or function does. .DESCRIPTION – a more detailed explanation of what the script or function does. .PARAMETER name – an explanation of a specific parameter. Replace name with the parameter name. You can have one of these sections for each parameter the script or function uses. .EXAMPLE – an example of how to use the script or function. You can have multiple .EXAMPLE sections if you want to provide more than one example. .NOTES – any miscellaneous notes on using the script or function. .LINK – a cross-reference to another help topic; you can have more than one of these. If you include a URL beginning with http:// or https://, the shell will open that URL when the Help command’s –online parameter is used. #>
  • 80. 80
  • 81. 81 Find custom commands this way Refresh the command list Actions you can take once you fill in parameters
  • 82. 82 More Good Ideas Always read scripts before running them Make it safe for others to not read them first Write scripts as functions most of the time Check for valid parameter values Do error handling
  • 83. 83 Demo Writing Functions Using Comments for Documentation
  • 84. TFS DEMO Check In, Out, Diff
  • 85. 85
  • 86. 86 Now for More Examples Jack’s take on Doc Lib Versioning – reporting & setting Bulk Site Creation Email Logging SSL Cert Expiration Warning Deploy WSPs
  • 87. DEMO Doc Lib Versioning
  • 88. 88 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
  • 89. 89 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!
  • 90. DEMO Bulk Site Creation
  • 91. Jack’s Favorite Scripts Logging, Deployment, & more
  • 92. 92 Chapter 5
  • 93. Resources Microsoft Resources 3rd Party Resources
  • 94. 94
  • 95. 95
  • 96. 96
  • 97. 97
  • 98. 98
  • 99. 99
  • 100. 100
  • 101. 101
  • 102. 102 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
  • 103. 103 Script something today! It’s Easy to Get Started! Learn & Use the PowerShell Syntax More Resources In Review…
  • 104. 104 Questions & Thank You • Michael Blumenthal SharePoint Architect PSC Group, LLC • MBlumenthal@psclist ens.com • psclistens.com • www.cspug.org • Twitter: @MichaelBL • SPYam • Jack Fruh SharePoint Admin • Jack@SharepointJack. com • SPSChicagoSuburbs.com • SharePointJack.com • Twitter: @SharePointJack • SPYam Thank you for your time today.