Wednesday, June 3, 2020

#96: What are new features in Powershell 7?

Powershell 7 comes with a set of new features that are very useful and I am eagerly waiting it to install in my environments so that I can use them.

(1) Ternary Operator

$message = (Test-Path $path) ? "Path exists" : "Path not found"


(2) Parallel execution in For-each

$logNames = 'Security','Application','System','Windows PowerShell','Microsoft-Windows-Store/Operational' $logEntries = $logNames | ForEach-Object -Parallel { Get-WinEvent -LogName $_ -MaxEvents 10000 } -ThrottleLimit 5 $logEntries.Count 50000

(3) Pipeline Chain Opertors

Write-Output 'First' && Write-Output 'Second'


(4) Get-Error Cmdlet

$Error | Get-Error

(5) Null coalescing

$x = $null $x ?? 100 100


Reference: 
https://docs.microsoft.com/en-us/powershell/scripting/whats-new/what-s-new-in-powershell-70?view=powershell-7


How to install Powershell 7.0?

You can download it from Microsoft's Github:
https://github.com/PowerShell/PowerShell/releases


Happy scripting!!

No comments:

Post a Comment

#112: How to handle xml document in Powershell?

 In PowerShell, you can handle XML data using various cmdlets and methods provided by the .NET Framework. Here's a basic guide on how to...