PowerShell: Bringing DevOps to Windows

PowerShell: Bringing DevOps to Windows

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

35e74c48a612d8a6786f8ab6424b49a1?s=128

Kevin Berridge

August 19, 2016
Tweet

Transcript

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

    Software
  2. PowerShell

  3. DevOps

  4. Productivity

  5. PowerShell

  6. Foundation Possibilities

  7. PowerShell: Bringing DevOps to Windows! Linux Mac

  8. The Shell Scripting

  9. The Shell

  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*
  11. None
  12. None
  13. None
  14. None
  15. None
  16. None
  17. None
  18. None
  19. None
  20. None
  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
  22. More Advanced Shell

  23. Change .txt files to .ext files

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

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

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

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

    }
  35. Main Pipeline Commands • ForEach-Object (%) • Where-Object (?) •

    Sort-Object (sort) • Select-Object (select)
  36. None
  37. None
  38. How do we run a regular command line app?

  39. None
  40. What dlls did msbuild build?

  41. None
  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
  43. Scripting

  44. PSAKE

  45. None
  46. None
  47. msbuild /v:m &”msbuild” /v:m iex ”msbuild /v:m”

  48. None
  49. None
  50. None
  51. None
  52. None
  53. PowerShell C# -eq == -ne != -gt > -ge >=

    -lt < -le <= -like Regex -notlike -match -contains Linq
  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
  55. .NET

  56. Store an encrypted string in an environment variable

  57. Set-EncryptedEnvironmentVariable.ps1

  58. None
  59. Summary • PowerShell is a .NET language • You can

    use anything in .NET from PowerShell
  60. Possibilities

  61. Collect log records and send a nightly email

  62. None
  63. None
  64. None
  65. Automate the execution of database migrations

  66. migration-connections.xml

  67. deploy-migrations.ps1

  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!
  69. PowerShell: Bringing DevOps to Windows! Kevin Berridge @kberridge Matrix Pointe

    Software