Upgrade to Pro — share decks privately, control downloads, hide ads and more …

PowerShell: Bringing DevOps to Windows

PowerShell: Bringing DevOps to Windows

An introduction to the foundations and possibilities of PowerShell! As presented at Abstractions.io.

Kevin Berridge

August 19, 2016
Tweet

More Decks by Kevin Berridge

Other Decks in Programming

Transcript

  1. PowerShell: Bringing
    DevOps to Windows!
    Kevin Berridge @kberridge
    Matrix Pointe Software

    View Slide

  2. PowerShell

    View Slide

  3. DevOps

    View Slide

  4. Productivity

    View Slide

  5. PowerShell

    View Slide

  6. Foundation
    Possibilities

    View Slide

  7. PowerShell: Bringing
    DevOps to Windows!
    Linux
    Mac

    View Slide

  8. The Shell
    Scripting

    View Slide

  9. The Shell

    View Slide

  10. Basic Shell Commands and Aliases
    PowerShell
    Command
    PowerShell
    Alias
    DOS Equivalent Unix Equivalent
    Set-Location sl cd* cd*
    Get-ChildItem gci dir* ls*
    Copy-Item cpi copy* cp*
    Move-Item mi move* mv*
    Remove-Item ri del* rm*
    Get-Content gc type* cat*
    Get-Help help help* man*

    View Slide

  11. View Slide

  12. View Slide

  13. View Slide

  14. View Slide

  15. View Slide

  16. View Slide

  17. View Slide

  18. View Slide

  19. View Slide

  20. View Slide

  21. Summary
    • Aliases are nice because they are short, also they match what
    you already know
    • Tab key auto completion is wonderful
    • The help command will teach you what you need to know

    View Slide

  22. More Advanced Shell

    View Slide

  23. Change .txt files to .ext files

    View Slide

  24. ls *cmd*.txt | %{ mv $_ ($_.BaseName + ".ext" ) }

    View Slide

  25. View Slide

  26. View Slide

  27. View Slide

  28. ls *cmd*.txt | %{ mv $_ ($_.BaseName + ".ext" ) }

    View Slide

  29. View Slide

  30. ls *cmd*.txt | %{ mv $_ ($_.BaseName + ".ext" ) }

    View Slide

  31. View Slide

  32. View Slide

  33. View Slide

  34. ls *cmd*.txt | %{ mv $_ ($_.BaseName + ".ext" ) }

    View Slide

  35. Main Pipeline Commands
    • ForEach-Object (%)
    • Where-Object (?)
    • Sort-Object (sort)
    • Select-Object (select)

    View Slide

  36. View Slide

  37. View Slide

  38. How do we run a regular command line app?

    View Slide

  39. View Slide

  40. What dlls did msbuild build?

    View Slide

  41. View Slide

  42. Summary
    • Commandlets return objects
    • DOS command return strings
    • “|” lets you easily chain commands together over those
    objects
    • Get-Member will tell you what those objects can do
    • %, ?, sort, select

    View Slide

  43. Scripting

    View Slide

  44. PSAKE

    View Slide

  45. View Slide

  46. View Slide

  47. msbuild /v:m
    &”msbuild” /v:m
    iex ”msbuild /v:m”

    View Slide

  48. View Slide

  49. View Slide

  50. View Slide

  51. View Slide

  52. View Slide

  53. PowerShell C#
    -eq ==
    -ne !=
    -gt >
    -ge >=
    -lt <
    -le <=
    -like Regex
    -notlike
    -match
    -contains Linq

    View Slide

  54. Summary
    • Scripts are no different than the shell!
    • $variables
    • Use functions just like commandlets
    • Comparison operators
    • & and Invoke-Expression
    • $lastexitcode vs. exceptions
    • PSAKE: make for PowerShell

    View Slide

  55. .NET

    View Slide

  56. Store an encrypted string in
    an environment variable

    View Slide

  57. Set-EncryptedEnvironmentVariable.ps1

    View Slide

  58. View Slide

  59. Summary
    • PowerShell is a .NET language
    • You can use anything in .NET from PowerShell

    View Slide

  60. Possibilities

    View Slide

  61. Collect log records
    and send a nightly email

    View Slide

  62. View Slide

  63. View Slide

  64. View Slide

  65. Automate the execution of
    database migrations

    View Slide

  66. migration-connections.xml

    View Slide

  67. deploy-migrations.ps1

    View Slide

  68. Honorable Mentions
    •PowerShell Remoting
    SSH for Windows!
    •PS Read Line
    Better editing at the shell!
    •Set-PSBreakpoint
    Integrated debugging!
    •Desired State Configuration (DSC)
    Chef/Puppet for PowerShell!

    View Slide

  69. PowerShell: Bringing
    DevOps to Windows!
    Kevin Berridge @kberridge
    Matrix Pointe Software

    View Slide