- SmartDeploy: Rethinking software deployment to remote workers in times of a pandemic - Thu, Jul 30 2020
- Outlook attachments now blocked in Office 365 - Tue, Nov 19 2019
- PolicyPak MDM Edition: Group Policy and more for BYOD - Tue, Oct 29 2019
There are several ways to deploy PowerShell 4. You could build it into your image, use SCCM, or Group Policy scripts. Because Group Policy scripts are universally accessible and free, we will use them to deploy PowerShell 4.
In the Group Policy Management Console, create a new GPO named APP Windows Management Framework 4. Create a security group with the same name and scope it to the GPO. Populate this group with a few test computers.
The WMF4 Deployment GPO
PowerShell 4, part of the Windows Management Framework (WMF), has one application dependency. It requires .Net Framework 4.5 to be installed first. If .Net Framework 4.5 is not installed beforehand, clients will successfully process part of the update but will not completely install PowerShell 4.
Deploying .Net Framework 4.5 ^
Before we go any further, download the offline installer for .Net Framework 4.5. Save the installer to a network share accessible to your domain computers. When .Net Framework 4.5 is installed, it will register itself in HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework\v4.0.30319\SKUs as .NETFramework,Version=v4.5”. We can use REG QUERY to check to see if this key exists.
@ECHO OFF REM Check to see if .Net Framework 4.5 is installed REG QUERY "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework\v4.0.30319\SKUs\.NETFramework,Version=v4.5"
If this registry key exist, %errorlevel% will equal zero. To prevent installing .Net Framework 4.5 over and over again, we can use: IF %errorlevel%==1 GOTO INSTALLNET
Finally, we just need to insert our silent install command and tie the first script together:
@ECHO OFF REM Check to see if .Net Framework 4.5 is installed REG QUERY "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework\v4.0.30319\SKUs\.NETFramework,Version=v4.5" IF %errorlevel%==1 GOTO INSTALLNET IF %errorlevel%==0 GOTO EXIT :INSTALLNET Start /wait dotNetFx45_Full_setup.exe /CEIPconsent /norestart /q :EXIT exit
Save this script as a batch file and add it as a shutdown script to your GPO.
GPO shutdown script
Deploying Windows Management Framework 4 ^
As we stated above, PowerShell 4 is installed when Windows Management Framework 4 is installed. WMF can be downloaded from here. The update comes in both architecture flavors; be sure to pick the one that matches your environment.
Downloading the X64 version of WMF 4
Because the package is a .MSU, we will use the Windows Update Standalone Installer (WUSA.exe). A quiet and passive restart install would look like this:
wusa.exe "Windows6.1-KB2819745-x64-MultiPkg.msu" /quiet /norestart
When PowerShell 4 is completely installed, we can query HKLM\SOFTWARE\Microsoft\PowerShell\3\PowerShellEngine for the PowerShellVersion string. The value of this string should be 4.0
PowerShell version in Registry
Like before, we can use REG QUERY to check this key and then check %errorlevel% to ensure a value was found.
@ECHO OFF REG QUERY "HKLM\SOFTWARE\Microsoft\PowerShell\3\PowerShellEngine" /f 4.0 IF %errorlevel%==1 GOTO INSTALLWMF IF %errorlevel%==0 GOTO EXIT :INSTALLWMF Start /wait wusa.exe "Windows6.1-KB2819745-x64-MultiPkg.msu" /quiet /norestart :EXIT Exit
Save this batch file and add it to your GPO as a shutdown script.
Shutdown script always run synchronously so .Net Framework will install before Windows Management Framework. By using these two scripts, you can deploy PowerShell 4 with Group Policy scripts.