Getting PowerShell MSI file
PowerShell has been around for years enabling task automation in Windows world. Through these years PowerShell has evolved to become cross platform scripting language, which means it can now run on Linux and MacOS through its 'Core' version. If you want to learn more about PowerShell core, I have already written this blog for you. In this blog, we will see how we can install PowerShell core though script using the MSI file. You can use this method to silently install PowerShell core on local as well as multiple remote systems. If you want to install PowerShell using GUI method, You can visit this blog.
Here, we will be installing PowerShell core 7.2.2 which is the latest stable version at the time of writing this blog, on Windows 11. You can download PowerShell core MSI file from here. You can also download this MSI file from PowerShell by using the script given below.
Invoke-WebRequest -Uri "https://github.com/PowerShell/PowerShell/releases/download/v7.2.2/PowerShell-7.2.2-win-x64.msi" -OutFile C:\Temp\PowerShell-7.2.2-win-x64.msi
Installing PowerShell Core
I am using Visual Studio code in this demo. You may use native PowerShell console to perform further steps. However, if you too want to use VS code, ensure that you have PowerShell extension installed in VS code.
Once you have the MSI file, you can use this file to check the options available for installation. You can do so by adding /? to the MSI file name. Here we will enter .\PowerShell-7.2.2-win-x64.msi /?.
Once you enter this, you will be presented with a dialog box, that will list out the options that are available to us. You can choose from multiple options including logging of the installation. For this demo, we will only be using quiet and passive switches. Quiet switch will do the installation silently and passive switch will display the progress bar.
You can also have additional options while installing using the MSI file. MSI packages can be installed from the command line allowing administrators to deploy packages without user interaction. The MSI package for PowerShell core includes the following properties to control the installation options:
ADD_EXPLORER_CONTEXT_MENU_OPENPOWERSHELL - This property controls the option for adding the Open PowerShell item to the context menu in Windows Explorer.
ADD_FILE_CONTEXT_MENU_RUNPOWERSHELL - This property controls the option for adding the Run with PowerShell item to the context menu in Windows Explorer.
ENABLE_PSREMOTING - This property controls the option for enabling PowerShell remoting during installation.
REGISTER_MANIFEST - This property controls the option for registering the Windows Event Logging manifest.
USE_MU - This property has two possible values:
1 (default) - Opts into updating through Microsoft Update, WSUS, or Configuration Manager
0 - Do not opt into updating through Microsoft Update, WSUS, or Configuration Manager
ENABLE_MU
1 (default) - Opts into using Microsoft Update for Automatic Updates
0 - Do not opt into using Microsoft Update
I will then use Start-Process command to initiate the installation. I will pass switches and options in Argumentlist parameter. I'll then hit enter and the installation will start.
Start-Process .\PowerShell-7.2.2-win-x64.msi -ArgumentList "/quiet /passive ADD_EXPLORER_CONTEXT_MENU_OPENPOWERSHELL=1 ENABLE_PSREMOTING=1 REGISTER_MANIFEST=1 USE_MU=1 ENABLE_MU=1"
You can install PowerShell core on remote machines using Invoke-command. The example given below will install PowerShell core on remote system named LabMachine2k19.
Invoke-Command -ComputerName LabMachine2k19 -ScriptBlock{Start-Process .\PowerShell-7.2.2-win-x64.msi -ArgumentList "/quiet /passiveADD_EXPLORER_CONTEXT_MENU_OPENPOWERSHELL=1 ENABLE_PSREMOTING=1 REGISTER_MANIFEST=1 USE_MU=1 ENABLE_MU=1"}
Verifying installation
Once the installation is completed, I will now go to start and search for pwsh. The PowerShell core icon here ensures PowerShell core is installed successfully on this system. However, we will still verify the version from VS code.
I will then restart VS code editor and once I'm in, I'll click on '+' sign to add a new terminal.
A new PowerShell core terminal start named 'pwsh'. VS code will use PowerShell core as it's default PowerShell.
I will then enter $PSVersionTable to check for the PowerShell version. Here, we can see PowerShell 7.2.2 is installed on this system.
This method can be used to deploy PowerShell core on multiple systems in your organization using any deployment tool that supports MSI installation or simply using Invoke-Command as shown in the above example.