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

Powershell für .NET Entwickler - Willkommen in der Welt von DevOps

Powershell für .NET Entwickler - Willkommen in der Welt von DevOps

Für viele .NET-Entwickler ist die Powershell noch immer ein Buch mit sieben Siegeln und wird oft in die Sysadmin-Ecke verstoßen. Schade eigentlich, denn die Powershell hat das Potenzial, den Entwickleralltag um einiges produktiver und angenehmer zu gestalten. Mal schnell 7 Frontend-Webserver neu starten? Eine virtuelle Maschine in Azure hochfahren? Aus den Services im Backend eine HTML-Datei generieren? Ein Backup einer SQL Server Datenbank erstellen? Auf der Webserver-Farm einen neuen Application Pool einrichten? Dies und noch vieles mehr geht in der Powershell mit einer einzigen Zeile Code! Und dabei spielt es noch nicht einmal eine Rolle, ob auf dem lokalen Rechner oder einem bzw. mehreren Servern gearbeitet wird. Mit dem wachsenden DevOps-Bedürfnis, welches nach dem Verschmelzen von Entwicklung und Betrieb strebt, wird die Powershell in Zukunft auch für Entwickler stark an Bedeutung gewinnen. Erweitern Sie ihre Werkzeugkiste mit diesem Power-Tool!

Manuel Meyer

June 27, 2017
Tweet

More Decks by Manuel Meyer

Other Decks in Programming

Transcript

  1. BASEL BERN BRUGG DÜSSELDORF FRANKFURT A.M. FREIBURG I.BR. GENF
    HAMBURG KOPENHAGEN LAUSANNE MÜNCHEN STUTTGART WIEN ZÜRICH
    Powershell für .NET Entwickler
    Developer Week DWX 2017
    Manuel Meyer, Trivadis AG
    http://manuelmeyer.net
    @manumeyer1

    View Slide

  2. Über mich
    • Consultant & Trainer für .NET
    bei der Trivadis AG
    • MVP für Visual Studio
    • C# / XAML, Integration, Azure,
    Troubleshooting & Performance
    Management
    Manuel Meyer
    http://manuelmeyer.net
    @manumeyer1

    View Slide

  3. Agenda
    1. Powershell Grundlagen
    2. Advanced Powershell
    (Remoting, WMI, COM, .NET,…)
    3. Powershell Use Cases

    View Slide

  4. Key Features
    • Automation
    • PS Remoting
    • .NET, COM, WMI, Perfcounters, EventLog, etc.
    • Integration in Produkten
    – Windows, IIS, SQL Server, TFS, Microsoft Azure,
    Exchange, Skype, Sharepoint.

    View Slide

  5. Die Shell
    • Powershell.exe
    • ISE
    • ISESteroids (commercial)
    – http://www.powertheshell.com/isesteroids/
    • PS Tools for Visual Studio
    • PowerGUI
    – https://software.dell.com/products/powergui-freeware/
    • VS Code

    View Slide

  6. Die Basics
    • Verb-Noun Commandlets
    Get-Process
    Get-NetFirewallProfile
    Set-Acl
    Set-AuthenticodeSignature
    Add-PhysicalDisk
    Show-EventLog

    View Slide

  7. Die Basics
    • Help
    • Objects
    • Pipelining
    • Output

    View Slide

  8. Mehr Basics
    • Comparison: -eq, -ne, -lt, -gt, -le, -ge, -contains,
    -notcontains
    • Arrays, HashTables
    • If-else, switch
    • For, foreach, while,
    do-while
    • Functions

    View Slide

  9. Agenda
    1. Powershell Grundlagen
    2. Advanced Powershell
    (Remoting, WMI, COM, .NET,…)
    3. Powershell Use Cases

    View Slide

  10. PS Remoting
    • Enter-PSSession
    • …-Computername LTMME02
    • Invoke-Command –Computername LTMME01,
    LTMME02, LTMME03 –Scriptblock { }

    View Slide

  11. COM Interop
    • Speech
    • Excel Interop

    View Slide

  12. WMI
    Windows Management Instrumentation
    “…a set of extensions to the
    Windows Driver Model that
    provides an operating system
    interface…”

    View Slide

  13. Providers
    • Get-PSProviders
    – Environment
    – FileSystem
    – Registry
    – Certificate
    – IIS
    – SqlServer
    – …

    View Slide

  14. .NET
    • Zugriff auf .NET Klassen
    • Web Services
    • Load Assembly and Show UI
    • WPF Samples.

    View Slide

  15. PS Workflows
    • Based on .NET Workflow Foundation
    • Long-running, persistable
    • Interrupt, suspend, resume
    • Sequence, Parallel, Foreach, etc…

    View Slide

  16. Agenda
    1. Powershell Grundlagen
    2. Advanced Powershell
    (Remoting, WMI, COM, .NET,…)
    3. Powershell Use Cases

    View Slide

  17. Git
    • PoSh-Git
    – https://github.com/dahlbyk/posh-git
    – http://haacked.com/archive/2011/12/13/better-git-with-
    powershell.aspx/

    View Slide

  18. Windows Server
    • Roles & Features
    Get-WindowsFeature/Install-WindowsFeature/Uninstall-
    WindowsFeature
    Install-WindowsFeature Web-Server -
    IncludeAllSubFeature -IncludeManagementTools
    'WebSrv01', 'WebSrv02', 'WebSrv03' | ForEach-Object
    {Install-WindowsFeature Web-Server -IncludeAllSubFeature
    -IncludeManagementTools -ComputerName $_}

    View Slide

  19. Windows Server
    Install-WindowsFeature
    -ConfigurationFilePath
    d:\WebServerConfigFile.xml

    View Slide

  20. IIS
    • Add, change, remove
    – Application pools
    – Web Sites
    – Virtual Directories
    – Web Applications
    – Website Bindings
    • Backup & Restore
    – Web Configuration
    Import-Module WebAdministration

    View Slide

  21. Sql Server
    (oder SSMS)
    • Execute T-SQL
    • Backup & Restore DBs
    • Generate Scripts for DB, Tables, Procedures.
    Import-Module SQLPS

    View Slide

  22. TFS
    • Get info
    – Work Items
    – Source Control
    • Manage
    – Workspaces
    – Changesets, Shelvesets, Pending Changes
    – Build Definitions
    – …

    View Slide

  23. Sharepoint
    • Install Sharepoint
    • Manage
    – Site Collections
    – Lists
    – …
    • Import/Export.

    View Slide

  24. Microsoft Azure

    View Slide

  25. Microsoft Azure
    • Manage
    – Storage
    – VMs
    – WebSites
    – Active Directory
    – …
    • Create multi-tier IaaS environments
    • KUDU.

    View Slide

  26. Die Basics

    View Slide

  27. Weiteres…
    • Samples zum Talk:
    – http://manuelmeyer.net/tag/powershell/
    • PSCX Powershell Community Extensions
    – http://pscx.codeplex.com/
    • PoShServer: A Powershell Web Server
    – http://poshserver.net/
    • PoShConsole: A WPF PS Console
    – https://poshconsole.codeplex.com

    View Slide

  28. BASEL BERN BRUGG DÜSSELDORF FRANKFURT A.M. FREIBURG I.BR. GENF
    HAMBURG KOPENHAGEN LAUSANNE MÜNCHEN STUTTGART WIEN ZÜRICH
    Powershell für .NET Entwickler
    Developer Week DWX 2017
    Manuel Meyer, Trivadis AG
    http://manuelmeyer.net
    @manumeyer1

    View Slide