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 full-size slide

  2. Productivity

    View full-size slide

  3. Foundation
    Possibilities

    View full-size slide

  4. PowerShell: Bringing
    DevOps to Windows!
    Linux
    Mac

    View full-size slide

  5. The Shell
    Scripting

    View full-size slide

  6. 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 full-size slide

  7. 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 full-size slide

  8. More Advanced Shell

    View full-size slide

  9. Change .txt files to .ext files

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  16. What dlls did msbuild build?

    View full-size slide

  17. 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 full-size slide

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

    View full-size slide

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

    View full-size slide

  20. 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 full-size slide

  21. Store an encrypted string in
    an environment variable

    View full-size slide

  22. Set-EncryptedEnvironmentVariable.ps1

    View full-size slide

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

    View full-size slide

  24. Possibilities

    View full-size slide

  25. Collect log records
    and send a nightly email

    View full-size slide

  26. Automate the execution of
    database migrations

    View full-size slide

  27. migration-connections.xml

    View full-size slide

  28. deploy-migrations.ps1

    View full-size slide

  29. 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 full-size slide

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

    View full-size slide