Created
April 13, 2016 14:08
-
-
Save Hexalon/d25ab0d07f6f9ef178c14a806474206e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# | |
.NOTES | |
=========================================================================== | |
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2015 v4.2.89 | |
Created on: 7/30/2015 12:48 PM | |
Created by: Colin Squier <[email protected] | |
Filename: Install-WMF4.ps1 | |
=========================================================================== | |
.DESCRIPTION | |
Automates installation of PowerShell 4. | |
#> | |
<# | |
.SYNOPSIS | |
Returns the path of the executing script's directory. | |
.DESCRIPTION | |
Sapien's implementation of the variable $HostInvocation | |
causes a conflict the with the system's variable. | |
.EXAMPLE | |
PS C:\> Get-ScriptDirectory | |
.NOTES | |
Work around for handling Sapien's custom host environment. | |
#> | |
function Get-ScriptDirectory | |
{ | |
if ($HostInvocation -ne $null) | |
{ | |
Split-Path $HostInvocation.MyCommand.path | |
} | |
else | |
{ | |
#$Invocation = (Get-Variable MyInvocation -Scope 1).Value | |
#Split-Path $Invocation.MyInvocation.path | |
Split-Path $script:MyInvocation.MyCommand.Path | |
} | |
} | |
If (-NOT ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole(` | |
[Security.Principal.WindowsBuiltInRole] "Administrator")) | |
{ | |
Write-Warning "You do not have Administrator rights to run this script!`nPlease re-run this script as an Administrator!" | |
Break | |
} | |
$RequiredOSVersion = "6.1.7601" | |
$OS = (Get-WmiObject -Class Win32_OperatingSystem) | |
$scriptDirectory = Get-ScriptDirectory | |
$Source = (Split-Path -Path $scriptDirectory -Parent) | |
$PackagePath = (Join-Path -Path $Source -ChildPath "ComputerSetup\WMF4") | |
$File32 = "Windows6.1-KB2819745-x86-MultiPkg.msu" | |
$File64 = "Windows6.1-KB2819745-x64-MultiPkg.msu" | |
$Product = "Windows Management Framework 4" | |
$FullPath32 = Join-Path -Path $PackagePath -ChildPath $File32 | |
$FullPath64 = Join-Path -Path $PackagePath -ChildPath $File64 | |
$Version = [Environment]::Version | |
$Version = $Version.Major | |
If ($Version -ge 4) | |
{ | |
Write-Host "$Product or later already installed." -ForegroundColor Green | |
break | |
} | |
If ([version]$OS.Version -eq $RequiredOSVersion) | |
{ | |
#$HotFix = (Get-HotFix | Where-Object { $_.HotfixID -eq 'KB2506143' -or $_.HotfixID -eq 'KB2819745' }) | |
$HotFix = (Get-HotFix | Where-Object { $_.HotfixID -eq 'KB2819745' }) | |
if (!($HotFix -eq $null)) | |
{ | |
Write-Host "$Product or later already installed." -ForegroundColor Green | |
} | |
If ($($OS.OSArchitecture) -eq '32-bit') | |
{ | |
If ($HotFix -eq $null) | |
{ | |
Write-Host "Installing $Product" | |
$UpdateFile = Start-Process -FilePath "wusa.exe" -ArgumentList "`"$FullPath32`" /quiet /norestart" -Wait -Passthru | |
$ExitCode = $UpdateFile.ExitCode | |
Write-Host "$Product installer exit code: $ExitCode" | |
If ($ExitCode -eq 0) | |
{ | |
Write-Host "Installation completed successfully." -ForegroundColor Green | |
} | |
ElseIf ($ExitCode -eq 1602) | |
{ | |
Write-Host "The user canceled installation." -ForegroundColor White | |
} | |
ElseIf ($ExitCode -eq 1603) | |
{ | |
Write-Host "A fatal error occurred during installation." -ForegroundColor Red | |
} | |
ElseIf ($ExitCode -eq 1641) | |
{ | |
Write-Host "A restart is required to complete the installation. This message indicates success." -ForegroundColor Yellow | |
} | |
ElseIf ($ExitCode -eq 3010) | |
{ | |
Write-Host "A restart is required to complete the installation. This message indicates success." -ForegroundColor Yellow | |
} | |
ElseIf ($ExitCode -eq 5100) | |
{ | |
Write-Host "The user's computer does not meet system requirements." -ForegroundColor Red | |
} | |
} | |
} | |
Else | |
{ | |
If ($HotFix -eq $null) | |
{ | |
Write-Host "Installing $Product" | |
$UpdateFile = Start-Process -FilePath "wusa.exe" -ArgumentList "`"$FullPath64`" /quiet /norestart" -Wait -Passthru | |
$ExitCode = $UpdateFile.ExitCode | |
Write-Host "$Product installer exit code: $ExitCode" | |
If ($ExitCode -eq 0) | |
{ | |
Write-Host "Installation completed successfully." -ForegroundColor Green | |
} | |
ElseIf ($ExitCode -eq 1602) | |
{ | |
Write-Host "The user canceled installation." -ForegroundColor White | |
} | |
ElseIf ($ExitCode -eq 1603) | |
{ | |
Write-Host "A fatal error occurred during installation." -ForegroundColor Red | |
} | |
ElseIf ($ExitCode -eq 1641) | |
{ | |
Write-Host "A restart is required to complete the installation. This message indicates success." -ForegroundColor Yellow | |
} | |
ElseIf ($ExitCode -eq 3010) | |
{ | |
Write-Host "A restart is required to complete the installation. This message indicates success." -ForegroundColor Yellow | |
} | |
ElseIf ($ExitCode -eq 5100) | |
{ | |
Write-Host "The user's computer does not meet system requirements." -ForegroundColor Red | |
} | |
} | |
} | |
} | |
Else | |
{ | |
Write-Host "The user's computer does not meet system requirements." -ForegroundColor Red | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment