Automate successfully with PowerShell 7...PowerShell 7 - Introduction Windows Linux macOS.NET...

Post on 22-Aug-2021

49 views 1 download

transcript

www.scriptrunner.com

Make PowerShell a real solution. For you and your team.

Automate successfully with PowerShell 7

Heiko Brenn @heikobrennAchim Wieser @achimwieserAline Imhof @alien4219

Duration: approx. 45 minutes

Phones are muted during this webinar

You can pose questions via the chat function of GoToWebinar

We will answer your questions at the end of the presentation

You will get access to the presentation slidesand the webinar recording => Double Opt-In required!

Logicstics

Short profile Heiko Brenn

Product Expert & Head of International BusinessIn the IT industry for 25+ yearsMany years of experience as

AdministratorConsultantProduct Manager

Responsible for EMEA and North AmericaTechnical SalesConsultingPartner Management

Contact informationPhone: +49-162-4879156 and +1-6469806339Email: heiko.brenn@scriptrunner.comLinkedin: www.linkedin.com/in/HeikoBrennTwitter: twitter.com/heikobrennGitHub: github.com/HeikoBrenn

Agenda

What’s New In PowerShell 7

Windows PowerShell and PowerShell 7 side-by-side

How to use PowerShell 7 with ScriptRunner

What‘s New in PowerShell 7

SECRETS MANAGEMENT

ForEach-Object-Parallel

HIGHLIGHTS POWERSHELL AND LINUX

CHALLENGES

HELP AND ERROR

MESSAGES

INSTALLATION INTRODUCTION

NEW OPERATORS

PowerShell 7 - Introduction

Windows Linux macOS

.NET Framework .NET Core

Windows PowerShell2006 - today

PowerShell 72016 - today

It’s open sourceCross-platform automation with one single technology

WindowsLinux macOS

Many performance improvementsImproved error viewCompatibility with many Windows PowerShell modules (https://aka.ms/PSModuleCompat)New operatorsSecrets Management

PowerShell 7 - Highlights

https://github.com/PowerShell/PowerShell/releasesMSI package

msiexec.exe /package PowerShell-7.0.31-win-x64.msi /quiet ADD_EXPLORER_CONTEXT_MENU_OPENPOWERSHELL=1 ENABLE_PSREMOTING=1 REGISTER_MANIFEST=1

MSIX package (not officially supported)Add-AppxPackage PowerShell-<version>-win-<os-arch>.msix

ZIPAdvanced deployment scenarios

WinGet (preview)winget install --name PowerShell –exact

“Steve Lee One-Liner”iex "& { $(irm https://aka.ms/install-powershell.ps1) } -UseMSI"

PowerShell 7 – Installation (Windows)

PowerShell 7 – Installation (Linux)

# Install system componentssudo apt-get update sudo apt-get install -y curl gnupg apt-transport-https # Import the public repository GPG keyscurl https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add –# Register the Microsoft Product feedsudo sh -c 'echo "deb [arch=amd64] https://packages.microsoft.com/repos/microsoft-debian-stretch-prod stretch main" > /etc/apt/sources.list.d/microsoft.list‘ # Update the list of productssudo apt-get update # Install PowerShellsudo apt-get install -y powershell# Start PowerShellPwsh

What worked for me in WSL:sudo wget https://aka.ms/install-powershell.sh; sudo bash install-powershell.sh; rm install-powershell.sh

Parallel execution of pipeline inputParameter “-ThrottleLimit” limits the number of script blocks running in parallel (default: 5)Doesn’t improve performance in all cases (overhead)

Don’t use it for trivial scriptsExample use cases

Getting logs from multiple serversAccess multiple databasesParalleling synchronous REST calls

More info: https://devblogs.microsoft.com/powershell/powershell-foreach-object-parallel-feature/

PowerShell 7 – ForEach-Object –Parallel (1)

#Windows PowerShell 5

Measure-Command {

$port = ‘53','80’,’88’,’443'

$port | ForEach-Object{Test-NetConnection -ComputerName 172.30.5.10 -Port $_}

} | Select-Object Minutes,Seconds

#PowerShell 7

Measure-Command {

$port = ‘53','80’,’88’,’443'

$port | ForEach-Object -parallel{Test-NetConnection -ComputerName 172.30.5.10 -Port $_}

} | Select-Object Minutes,Seconds

PowerShell 7 – ForEach-Object –Parallel (2)

Officially supported distributionsUbuntu, Debian, Alpine, CentOS, RHEL, Fedora, openSUSE

Community supported distributionsArch Linux, Kali, Raspbian

SSH is key (https://www.thomasmaurer.ch/2019/04/setup-powershell-ssh-remoting-in-powershell-6/)Why use PowerShell on Linux?

Expanding your existing PowerShell know-how to new platformsIf you’re a Windows PowerShell guy that now also has to manage Linux machines (i.e. Azure, AWS)If you want to work with objects instead of strings

PowerShell 7 and Linux

Module for storing and retrieving credentialsUses Windows Credential StoreUses local user contextCan be extended with custom vaults

PowerShell 7 and Secrets Management

PowerShell 7 and Windows PowerShell side-by-side

Separate installation path and execution nameSeparate PSModulePath

PowerShell 7 Windows PowerShell

Event Log App log/PowerShellCore App log/Windows PowerShell

Module paths „%programfiles%\powershell\7\modules“ „%programfiles%\PowerShell\Modules“

Profile location „…\username\documents\PowerShell“ „…\username\documents\WindowsPowerShell“

Installation paths „%programfiles%\PowerShell\7“ “…\Windows\System32\WindowsPowerShell\v1.0”

Executables Pwsh.exe PowerShell.exe

Prefered IDE Visual Studio Code (+ Windows Terminal) ISE

Separate profiles for each versionSeparate Event logs

Ternary operator (a $ b : c)Simplified if-else statement<condition> ? <if-true> : <if-false>Examples

$total = 10 * 5 -eq 20 ? 'yes' : 'no’$IsMacOS ? 'You are on a Mac' : $IsLinux ? 'You are on Linux' : 'You must be on Windows’The “old” PowerShell 5 way:

If ($IsMacOS) {'You are on a Mac'

} elseif ($IsLinux) {'You are on Linux'

} else {'You must be on Windows'

}

PowerShell 7 – New Operators (1)

Pipeline chain operators (|| and &&)Conditionally chain pipelinesThe && operator executes the right-hand pipeline, if the left-hand pipeline succeeded. The || operator executes the right-hand pipeline if the left-hand pipeline failed.PowerShell 7Examples

PowerShell 5If (-Not [Bool](Get-ChildItem -Path "application.log")) {New-Item -Path "application.log" }PowerShell 7Get-ChildItem -Path "application.log" || New-Item -Path "application.log"

PowerShell 7 – New Operators (2)

Null conditional operators (?? and ??=)The null-coalescing operator ?? returns the value of its left-hand operand if it isn't null. Otherwise, it evaluates the right-hand operand and returns its result. The ?? operator doesn't evaluate its right-hand operand if the left-hand operand evaluates to non-null.Example 1

$x = $null$x ?? 100100

Example 2[string] $todaysDate = '1/10/2020’$todaysDate ?? (Get-Date).ToShortDateString()1/10/2020

PowerShell 7 – New Operators (3)

www.scriptrunner.com

Make PowerShell a real solution. For you and your team.

Demo: PowerShell 7

PowerShell 7 is not pre-installed on any Windows OS at the momentMany different deployment optionsNot all existing Windows PowerShell modules work with PS7

i.e. Import-Module AzureAD fails (https://docs.microsoft.com/en-us/office365/enterprise/powershell/connect-to-office-365-powershell)

Not all existing Windows PS Cmdlets are available in PS7 Setting up SSH Remoting for Linux can be….interesting

PowerShell 7 - Challenges

https://www.michev.info/Blog/Post/2912/powershell-7-is-out-office-365

https://docs.microsoft.com/en-us/powershell/scripting/install/installing-powershell-core-on-linux?view=powershell-7

https://www.thomasmaurer.ch/2019/04/setup-powershell-ssh-remoting-in-powershell-6/

https://devblogs.microsoft.com/powershell/announcing-powershell-7-0/

https://devblogs.microsoft.com/powershell/powershell-foreach-object-parallel-feature/

https://github.com/PowerShell/PowerShell/releases

https://docs.microsoft.com/en-us/powershell/scripting/install/installing-powershell?view=powershell-7

https://petri.com/understanding-and-using-the-powershell-7-foreach-parallel-option

https://www.cloudsavvyit.com/5037/powershell-7-cross-platform-best-practices/

https://toastit.dev/2020/03/11/ps7now-null-conditional/

Ressources

www.scriptrunner.com

Make PowerShell a real solution. For you and your team.

PowerShell 7 andScriptRunner

Challenges for IT Pros

PowerShell is a tool for IT experts only

No way to delegate tasks to service desk or end users

No centralized & securePowerShell management

Many recurring tasks still have to betaken over by IT Pros

Drown in daily business

Achieve More With PowerShell In 5 Steps

Centralize your PowerShell scripts

Manage credentials & permissions securely

Automatically transformPowerShell scripts into Web GUIs

Delegate recurring tasks to help desk and end users

Integrate with ITSM, Monitoring & Workflow systems and more

Windows PowerShell & PowerShell 7 with ScriptRunner

Windows Linux macOS

.NET Framework .NET Core

Windows PowerShell2006 - today

PowerShell 72016 - today

How to use PowerShell 7 in ScriptRunner in 3 steps

Install .NET Core 3.1(is part of our installation with next version)

Enable the ScriptRunner PS7 host (no longer necessary with next version)

Switch ScriptRunner Actionto „PowerShell 7“ mode

How to use PowerShell 7 with Linux in ScriptRunner

Install and configureWindows OpenSSH

Create a ScriptRunnerCredential for SSH

Create a new ScriptRunner targetfor your Linux machine

Select ScriptRunner Linux target

Switch ScriptRunner Action to „PowerShell 7“ mode

www.scriptrunner.com

Make PowerShell a real solution. For you and your team.

Demo: ScriptRunner and PowerShell 7

Password Server Support

Centralized password safesCyberArk Password VaultPleasant Password ServerThycotic Secret Server

No credentials are stored locallyAutomatic password rotationEasy one secure password repository for multiple ScriptRunner servers

Secure Delegation

https://www.scriptrunner.com/de/software/system/

Domain userwith NO

privilegedpermissions

ScriptRunner – Make PowerShell A Real Solution

HelpDeskDeveloper End UserAdmin DevOps

ScriptRunner – Sample scenario

Actions Create New Mailbox

Queries Select OU

Targets Exchange, Exchange Online

Scripts New-Mailbox.ps1

Credentials Service account with necessary permissions

Delegation Helpdesk user, End user

ScriptRunner – Practical Examples and Use Cases

scriptrunner.com/en/use-cases/

ScriptRunner – The components

ScriptDeveloper

DevOps Plugin

SysAdmin

Admin App

Service Desk

Delegate App

End User

Self-Service App

Integration

Connectors

Ready-made Scripts

ActionPacks

ScriptRunner – How the components play together

https://www.scriptrunner.com/en/software/system/

ScriptRunner – The Full Picture

https://www.scriptrunner.com/en/software/system/

ScriptRunner test report fom a Microsoft MVP

https://www.adamtheautomator.com/scriptrunner-bringing-powershell-to-devops/

Adam Bertram aka Adam The AutomatorMicrosoft MVP Cloud and Datacenter Management

“ScriptRunner is a master of organizing, categorizing and delegating scripts.”

“If you are looking into automating your administration and support processes easily and securely, you will find a powerful and professional tool here.”

“ScriptRunner is a real DevOps tool for PowerShell scripters.”

“to get the same functionality of ScriptRunner, it would require several applications to get a similar feature set.”

“Compared to large automation platforms, ScriptRunner is significantly cheaper.”

Use cases with and without ScriptRunner

Get your free PowerShell poster

https://lp.scriptrunner.com/en/powershell-poster

Next Steps

Read the LinkedIn article „2020 – Finally the year ofIT automation?“ https://bit.ly/2NNkc88

Start testing ScriptRunner: lp.scriptrunner.com/en/demo-download

Book a online demo session with me: lp.scriptrunner.com/meetings/heiko-brenn/demo-en

Start using hundreds of ready-made PowerShell scripts: https://github.com/scriptrunner/ActionPacks

www.scriptrunner.comScriptRunner – Make PowerShell a real solution. For you and your team.

Thank you.

© ScriptRunner Software GmbHLudwig-Erhard-Straße 2 | 76275 Ettlingen | Germany

Tel: +49 (0) 7243 34887-0 Mail: info@scriptrunner.com