+ All Categories
Home > Documents > Automate successfully with PowerShell 7...PowerShell 7 - Introduction Windows Linux macOS.NET...

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

Date post: 22-Aug-2021
Category:
Upload: others
View: 49 times
Download: 1 times
Share this document with a friend
40
www.scriptrunner.com Make PowerShell a real solution. For you and your team. Automate successfully with PowerShell 7 Heiko Brenn @heikobrenn Achim Wieser @achimwieser Aline Imhof @alien4219
Transcript
Page 1: Automate successfully with PowerShell 7...PowerShell 7 - Introduction Windows Linux macOS.NET Framework.NET Core Windows PowerShell 2006 - today PowerShell 7 2016 - today It’s open

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

Page 2: Automate successfully with PowerShell 7...PowerShell 7 - Introduction Windows Linux macOS.NET Framework.NET Core Windows PowerShell 2006 - today PowerShell 7 2016 - today It’s open

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

Page 3: Automate successfully with PowerShell 7...PowerShell 7 - Introduction Windows Linux macOS.NET Framework.NET Core Windows PowerShell 2006 - today PowerShell 7 2016 - today It’s open

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: [email protected]: www.linkedin.com/in/HeikoBrennTwitter: twitter.com/heikobrennGitHub: github.com/HeikoBrenn

Page 4: Automate successfully with PowerShell 7...PowerShell 7 - Introduction Windows Linux macOS.NET Framework.NET Core Windows PowerShell 2006 - today PowerShell 7 2016 - today It’s open

Agenda

What’s New In PowerShell 7

Windows PowerShell and PowerShell 7 side-by-side

How to use PowerShell 7 with ScriptRunner

Page 5: Automate successfully with PowerShell 7...PowerShell 7 - Introduction Windows Linux macOS.NET Framework.NET Core Windows PowerShell 2006 - today PowerShell 7 2016 - today It’s open

What‘s New in PowerShell 7

SECRETS MANAGEMENT

ForEach-Object-Parallel

HIGHLIGHTS POWERSHELL AND LINUX

CHALLENGES

HELP AND ERROR

MESSAGES

INSTALLATION INTRODUCTION

NEW OPERATORS

Page 6: Automate successfully with PowerShell 7...PowerShell 7 - Introduction Windows Linux macOS.NET Framework.NET Core Windows PowerShell 2006 - today PowerShell 7 2016 - today It’s open

PowerShell 7 - Introduction

Windows Linux macOS

.NET Framework .NET Core

Windows PowerShell2006 - today

PowerShell 72016 - today

Page 7: Automate successfully with PowerShell 7...PowerShell 7 - Introduction Windows Linux macOS.NET Framework.NET Core Windows PowerShell 2006 - today PowerShell 7 2016 - today It’s open

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

Page 8: Automate successfully with PowerShell 7...PowerShell 7 - Introduction Windows Linux macOS.NET Framework.NET Core Windows PowerShell 2006 - today PowerShell 7 2016 - today It’s open

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)

Page 9: Automate successfully with PowerShell 7...PowerShell 7 - Introduction Windows Linux macOS.NET Framework.NET Core Windows PowerShell 2006 - today PowerShell 7 2016 - today It’s open

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

Page 10: Automate successfully with PowerShell 7...PowerShell 7 - Introduction Windows Linux macOS.NET Framework.NET Core Windows PowerShell 2006 - today PowerShell 7 2016 - today It’s open

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)

Page 11: Automate successfully with PowerShell 7...PowerShell 7 - Introduction Windows Linux macOS.NET Framework.NET Core Windows PowerShell 2006 - today PowerShell 7 2016 - today It’s open

#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)

Page 12: Automate successfully with PowerShell 7...PowerShell 7 - Introduction Windows Linux macOS.NET Framework.NET Core Windows PowerShell 2006 - today PowerShell 7 2016 - today It’s open

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

Page 13: Automate successfully with PowerShell 7...PowerShell 7 - Introduction Windows Linux macOS.NET Framework.NET Core Windows PowerShell 2006 - today PowerShell 7 2016 - today It’s open

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

PowerShell 7 and Secrets Management

Page 14: Automate successfully with PowerShell 7...PowerShell 7 - Introduction Windows Linux macOS.NET Framework.NET Core Windows PowerShell 2006 - today PowerShell 7 2016 - today It’s open

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

Page 15: Automate successfully with PowerShell 7...PowerShell 7 - Introduction Windows Linux macOS.NET Framework.NET Core Windows PowerShell 2006 - today PowerShell 7 2016 - today It’s open

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)

Page 16: Automate successfully with PowerShell 7...PowerShell 7 - Introduction Windows Linux macOS.NET Framework.NET Core Windows PowerShell 2006 - today PowerShell 7 2016 - today It’s open

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)

Page 17: Automate successfully with PowerShell 7...PowerShell 7 - Introduction Windows Linux macOS.NET Framework.NET Core Windows PowerShell 2006 - today PowerShell 7 2016 - today It’s open

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)

Page 18: Automate successfully with PowerShell 7...PowerShell 7 - Introduction Windows Linux macOS.NET Framework.NET Core Windows PowerShell 2006 - today PowerShell 7 2016 - today It’s open

www.scriptrunner.com

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

Demo: PowerShell 7

Page 19: Automate successfully with PowerShell 7...PowerShell 7 - Introduction Windows Linux macOS.NET Framework.NET Core Windows PowerShell 2006 - today PowerShell 7 2016 - today It’s open

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

Page 20: Automate successfully with PowerShell 7...PowerShell 7 - Introduction Windows Linux macOS.NET Framework.NET Core Windows PowerShell 2006 - today PowerShell 7 2016 - today It’s open

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

Page 21: Automate successfully with PowerShell 7...PowerShell 7 - Introduction Windows Linux macOS.NET Framework.NET Core Windows PowerShell 2006 - today PowerShell 7 2016 - today It’s open

www.scriptrunner.com

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

PowerShell 7 andScriptRunner

Page 22: Automate successfully with PowerShell 7...PowerShell 7 - Introduction Windows Linux macOS.NET Framework.NET Core Windows PowerShell 2006 - today PowerShell 7 2016 - today It’s open

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

Page 23: Automate successfully with PowerShell 7...PowerShell 7 - Introduction Windows Linux macOS.NET Framework.NET Core Windows PowerShell 2006 - today PowerShell 7 2016 - today It’s open

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

Page 24: Automate successfully with PowerShell 7...PowerShell 7 - Introduction Windows Linux macOS.NET Framework.NET Core Windows PowerShell 2006 - today PowerShell 7 2016 - today It’s open

Windows PowerShell & PowerShell 7 with ScriptRunner

Windows Linux macOS

.NET Framework .NET Core

Windows PowerShell2006 - today

PowerShell 72016 - today

Page 25: Automate successfully with PowerShell 7...PowerShell 7 - Introduction Windows Linux macOS.NET Framework.NET Core Windows PowerShell 2006 - today PowerShell 7 2016 - today It’s open

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

Page 26: Automate successfully with PowerShell 7...PowerShell 7 - Introduction Windows Linux macOS.NET Framework.NET Core Windows PowerShell 2006 - today PowerShell 7 2016 - today It’s open

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

Page 27: Automate successfully with PowerShell 7...PowerShell 7 - Introduction Windows Linux macOS.NET Framework.NET Core Windows PowerShell 2006 - today PowerShell 7 2016 - today It’s open

www.scriptrunner.com

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

Demo: ScriptRunner and PowerShell 7

Page 28: Automate successfully with PowerShell 7...PowerShell 7 - Introduction Windows Linux macOS.NET Framework.NET Core Windows PowerShell 2006 - today PowerShell 7 2016 - today It’s open

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

Page 29: Automate successfully with PowerShell 7...PowerShell 7 - Introduction Windows Linux macOS.NET Framework.NET Core Windows PowerShell 2006 - today PowerShell 7 2016 - today It’s open

Secure Delegation

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

Domain userwith NO

privilegedpermissions

Page 30: Automate successfully with PowerShell 7...PowerShell 7 - Introduction Windows Linux macOS.NET Framework.NET Core Windows PowerShell 2006 - today PowerShell 7 2016 - today It’s open

ScriptRunner – Make PowerShell A Real Solution

HelpDeskDeveloper End UserAdmin DevOps

Page 31: Automate successfully with PowerShell 7...PowerShell 7 - Introduction Windows Linux macOS.NET Framework.NET Core Windows PowerShell 2006 - today PowerShell 7 2016 - today It’s open

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

Page 32: Automate successfully with PowerShell 7...PowerShell 7 - Introduction Windows Linux macOS.NET Framework.NET Core Windows PowerShell 2006 - today PowerShell 7 2016 - today It’s open

ScriptRunner – Practical Examples and Use Cases

scriptrunner.com/en/use-cases/

Page 33: Automate successfully with PowerShell 7...PowerShell 7 - Introduction Windows Linux macOS.NET Framework.NET Core Windows PowerShell 2006 - today PowerShell 7 2016 - today It’s open

ScriptRunner – The components

ScriptDeveloper

DevOps Plugin

SysAdmin

Admin App

Service Desk

Delegate App

End User

Self-Service App

Integration

Connectors

Ready-made Scripts

ActionPacks

Page 34: Automate successfully with PowerShell 7...PowerShell 7 - Introduction Windows Linux macOS.NET Framework.NET Core Windows PowerShell 2006 - today PowerShell 7 2016 - today It’s open

ScriptRunner – How the components play together

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

Page 35: Automate successfully with PowerShell 7...PowerShell 7 - Introduction Windows Linux macOS.NET Framework.NET Core Windows PowerShell 2006 - today PowerShell 7 2016 - today It’s open

ScriptRunner – The Full Picture

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

Page 36: Automate successfully with PowerShell 7...PowerShell 7 - Introduction Windows Linux macOS.NET Framework.NET Core Windows PowerShell 2006 - today PowerShell 7 2016 - today It’s open

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.”

Page 37: Automate successfully with PowerShell 7...PowerShell 7 - Introduction Windows Linux macOS.NET Framework.NET Core Windows PowerShell 2006 - today PowerShell 7 2016 - today It’s open

Use cases with and without ScriptRunner

Page 38: Automate successfully with PowerShell 7...PowerShell 7 - Introduction Windows Linux macOS.NET Framework.NET Core Windows PowerShell 2006 - today PowerShell 7 2016 - today It’s open

Get your free PowerShell poster

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

Page 39: Automate successfully with PowerShell 7...PowerShell 7 - Introduction Windows Linux macOS.NET Framework.NET Core Windows PowerShell 2006 - today PowerShell 7 2016 - today It’s open

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

Page 40: Automate successfully with PowerShell 7...PowerShell 7 - Introduction Windows Linux macOS.NET Framework.NET Core Windows PowerShell 2006 - today PowerShell 7 2016 - today It’s open

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: [email protected]


Recommended