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!!
(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