Introduction to PowerShell at Chicago Code Camp 2014

374 views

Published on

An introduction to Microsoft's PowerShell scripting language.

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
374
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
6
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide
  • Every 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”V4 is here2003 -download20082008 R2, 2012+ISEV4
  • Does anyone have any other names for these?Victor Borge has his own take on these: http://www.youtube.com/watch?v=lF4qii8S3gwSymbolCalledSymbolCalled$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
  • begin with a $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?
  • 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
  • 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!
  • Introduction to PowerShell at Chicago Code Camp 2014

    1. 1. 2014 Introduction to PowerShell MICHAEL BLUMENTHAL PSC GROUP, LLC
    2. 2. 2014 Who is Michael Blumenthal? • Sr. Solution Architect at PSC Group • CSPUG Co-Leader • INETA Champ 2010-2013 • 19 years in IT Consulting • 7 years working with PowerShell • Twitter: @MichaelBL
    3. 3. 2014 Why PowerShell?
    4. 4. 2014 PowerShell puts the SharePoint Engine at your fingertips! • It’s Easy to Get Started!1 • Learn the PowerShell Syntax2 • Real World Examples3 • Best Practices4 • More Resources5
    5. 5. 2014 Chapter 1
    6. 6. 2014 Getting Started with PowerShell 2003 2008 2008 R2 2012 7, 8, 8.1
    7. 7. 2014 Windows Feature
    8. 8. 2014
    9. 9. 2014 PowerShell V3&4 ISE
    10. 10. 2014 Chapter 2
    11. 11. 2014 Learn to use PowerShell with SharePoint! Symbols & Keywords Using the SharePoint API Creating and Running Scripts
    12. 12. 2014 Symbols, Keywords, and Syntax! Oh My! • Variables1 • Commands2 • Piping3 • Comparisons4 • Flow Control5 • Filtering6
    13. 13. 2014 Punctuation Pronunciation $ _ : % # [ ] ( ) ; | . + = { } < > ! /, “ -
    14. 14. 2014 Pop Quiz… 1$#|
    15. 15. 2014 Variables • Case Insensitive, Dynamic typing $foo $true, $false, $profile, $null $foo = “Hello, World” 1
    16. 16. 2014
    17. 17. 2014 Commands are called cmdlets. Verb-Noun Built-in, Extensible Get-Help & Help Get-Member 2
    18. 18. 2014 Help!
    19. 19. 2014 The Power of Piping! Output Of Command 1 Input of Command 2 3
    20. 20. 2014 Example
    21. 21. 2014 Dial zero for an…4 Operator -eq -le -ne -like -gt -notlike -ge -match -lt -notmatch
    22. 22. 2014 Example
    23. 23. 2014 Taking Control of the Flow • 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 5
    24. 24. 2014 Example
    25. 25. 2014 Where-Object •Where {<Test>}Syntax • V1&2:Dir | Where {$_.Name –like “B*”} • V3:Dir | where Name –like B* Example 6
    26. 26. 2014 Executing Scripts .filename.ps1 Set-ExecutionPolicy Unrestricted
    27. 27. 2014 Chapter 3
    28. 28. 2014 Real World Examples • Flash cards • Dell Service Tag • Audio Alerts • MP3 Metadata Management • Managing Microsoft Server Products • File Conversion & Text Manipulation
    29. 29. 2014 Flash Cards
    30. 30. 2014 Get-DellServiceTag • Get-WmiObject win32_SystemEnclosure | select serialnumber
    31. 31. 2014 Audio Alerts • Stick this at the end of your long running script: $Voice = new-object -com SAPI.SpVoice $Voice.Speak(“Deployment is done!")
    32. 32. 2014 File and Text Wrangling • Word • Auto DOCX • RegEx • PSObj TXT • Export- • CSV CSV
    33. 33. 2014 Chapter 4
    34. 34. 2014 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. • #>
    35. 35. 2014 Find custom commands this way Refresh the command list Actions you can take once you fill in parameters
    36. 36. 2014 Self Announcing Functions …
    37. 37. 2014 Source Code Control
    38. 38. 2014 More Good Ideas • Always read scripts before running them • Make yours safe when others don’t • Check for valid parameter values • get-help about_Functions_Advanced_Parameters • Do error handling • get-help about_Try_Catch_Finally • get-help about_CommonParameters • -ErrorAction and -ErrorVariable
    39. 39. 2014 Chapter 5
    40. 40. 2014
    41. 41. 2014
    42. 42. 2014
    43. 43. 2014
    44. 44. 2014 Resources Summary  PowerShell Product Team Blog  TechNet Script Center  PowerShell in Action by Bruce Payette  CodePlex: PSBBs (mine)  CodePlex:SPInstaller  Blog.BlumenthalIT.Net  SharePointJack.com • Jeff Hicks • Gary LaPointe • Raymond Mitchell • Todd Klindt • POSHCODE.ORG • get-spscripts.com • SPYam
    45. 45. 2014 Script something today! It’s Easy to Get Started! Learn & Use the PowerShell Syntax More Resources In Review…
    46. 46. 2014 Questions • Michael Blumenthal SharePoint Architect PSC Group, LLC • MBlumenthal@psclistens.com • psclistens.com • www.cspug.org • Twitter: @MichaelBL • LinkedIn • Microsoft Midwest Customers Yammer Network Thank you for your time today.
    47. 47. 2014 In Memory of Dave Bost 6/30/1970-4/7/2014 Developer Evangelist at Microsoft for 8 years September 2005 – October 2013 He was a great supporter of the Chicago technical community. Please donate to his family’s chosen cause, Pitt Hopkins Research Foundation http://pitthopkins.org/donate/ More about Dave Bost’s passing: Obit: http://bit.ly/1msYRLR David Giard’s blog: http://bit.ly/1fhIvR2

    ×