PowerShell 7
After a long wait, Microsoft announced the release of PowerShell 7 on 3rd March 2020. Two variants of PowerShell that exists are Windows PowerShell 5.1 for Windows administration and PowerShell Core 6.2 for Linux and MacOS. Windows PowerShell was build on .NET framework and PowerShell Core was build on .NET Core.
PowerShell 7 is build on .NET Core 3.1, which is a successor of PowerShell Core 6.x and have brought in most of .NET Framework interfaces from Windows which greatly reduces the gap between the two variants. In Windows environment, for the modules which are not present in PowerShell 7, it can in turn initiate a session with Windows PowerShell 5.1 making it backward compatible. This makes PowerShell 7 a cross platform Scripting language and administration tool for Windows, Linux and MacOS.
Whats new in PowerShell 7 ?
1. Pipeline parallelization
ForEach-Object -parallel – Iterates through collection in parallel using -parallel parameter
2. Operators
Ternary operator – a ? b : c
condition ? true : false
Pipeline chain operators – || and &&
The && operator executes the right-hand pipeline if the left-hand pipeline succeeded. Likewise, the || operator only executes the right-hand pipeline if the left-hand pipeline fails.
Null coalescing operators – ?? and ??=
$a ?? “value is not assigned” – if $a is null, this will not throw any error, instead displays string right to ??
$a ??= 10 – if $a is null, then the variable is assigned with the value 10. Otherwise value assignment does not happen.
3. Error View
Simplified and dynamic error view
4. PowerShell Updates
Notify of new PowerShell version availability. By default, check once a day
One Liner to Silently install PowerShell
Invoke-Expression "& { $(invoke-webrequest https://aka.ms/install-powershell.ps1) } -Quiet -AddExplorerContextMenu -UseMSI"
One Liner to Install PowerShell 7 using GUI
Invoke-Expression "& { $(Invoke-WebRequest https://aka.ms/install-powershell.ps1) } -UseMSI"
The above command will download the msi file and open the package. Please follow the below installation instruction once the installer is running.
Installing PowerShell 7
Download the package
Use the below command to download the msi file or it can be downloaded from github too.
Invoke-WebRequest -Uri https://github.com/PowerShell/PowerShell/releases/download/v7.1.4/PowerShell-7.1.4-win-x64.msi -OutFile $home\Downloads\PowerShell-7.1.4-win-x64.msi
Above command will download the msi package to the downloads folder.
Install the MSI Package
Run the installer from the downloads folder
Click “Next”
Specify the installation folder and click “Next”. Default installation path is “C:\Program Files\PowerShell\”
Select additional options and click “Next”
- Add PowerShell to Path Environment Variable – Adds PowerShell to the Windows Path environment variable which allows you to call PowerShell from any other terminal.
- Register Windows Event Logging Manifest – Adds PowerShell to the Windows Event Logging Manifest and allows you to log events from PowerShell instance.
- Enable PowerShell Remoting – Enables PowerShell to run commands remotely.
- Add ‘Open here’ Context Menus to Explorer – Adds an option inside the right-click menu in explorer that opens an instance of PowerShell with the folder path.
Click in Install to proceed with installation. UAC Prompt will appear asking for administrator privileges to install the package. Click on “Yes” to continue.
Click on “Finish” to complete the installation.
How to open PowerShell 7
To open PowerShell 7, click on start button, search for pwsh.exe and press enter
or right click inside any explorer window to get PowerShell option.
PowerShell console opens with PowerShell 7 in the window
You are now ready to use the PowerShell 7
Thank you for reading my post. Hope this is helpful to you.
Recent Comments