Files
management-scripts/Start-PowerShellUpgrade.ps1
T
2019-11-11 19:22:39 -05:00

75 lines
2.8 KiB
PowerShell

#Requires -version 2
## Get the Windows version information
$WinVersion = "{0}.{1}" -f ([System.Environment]::OSVersion.Version).Major,([System.Environment]::OSVersion.Version).Minor
$WinBuild = ([System.Environment]::OSVersion.Version).Build
## Get PowerShell version information
$CurrentVersion = "{0}.{1}" -f $PSVersionTable.PSVersion.Major,$PSVersionTable.PSVersion.Minor
## Check the OS architecture
If ( Test-Path -PathType Container -Path ${env:ProgramFiles(x86)} ) { $Is64bit = $true } Else { $Is64bit = $false }
## Set a variable to make sure the current Windows version is supported
$InstallSupported = $true
Switch ( $WinVersion ) {
## Windows Vista
"6.0" {
If ( $Is64bit ) { $URL = 'https://download.microsoft.com/download/E/7/6/E76850B8-DA6E-4FF5-8CCE-A24FC513FD16/Windows6.0-KB2506146-x64.msu' }
Else { $URL = 'https://download.microsoft.com/download/E/7/6/E76850B8-DA6E-4FF5-8CCE-A24FC513FD16/Windows6.0-KB2506146-x86.msu' }
$UpgradeVersion = 3.0
; break }
## Windows 7
"6.1" {
## PowerShell 4.0
If ( $Is64bit ) { $URL = 'https://download.microsoft.com/download/3/D/6/3D61D262-8549-4769-A660-230B67E15B25/Windows6.1-KB2819745-x64-MultiPkg.msu' }
Else { $URL = 'https://download.microsoft.com/download/3/D/6/3D61D262-8549-4769-A660-230B67E15B25/Windows6.1-KB2819745-x86-MultiPkg.msu' }
$UpgradeVersion = 4.0
; break }
## Windows 8
#"6.2" {; break }
## Windows 8.1
#"6.3" {; break }
## Windows 10
#"10.0" {; break }
## Not Supported
default { $InstallSupported = $false ; break }
}
## Make sure installation is supported
If ( ($InstallSupported) -and ($CurrentVersion -lt $UpgradeVersion) ) {
## Get the file type so we install it the correct way
$FileType = ([System.IO.Path]::GetExtension($File)).ToUpper()
## Set the destination file for the downloaded package
$File = "${env:TEMP}\$(Split-Path -Leaf $URL)"
## Download the installation package
(New-Object Net.WebClient).DownloadFile($URL,$File)
If ( Test-Path $File ) {
## Get the file extension so we use the correct method to install the update
$FileType = [System.IO.Path]::GetExtension($File)
## Write a message so we know what version was upgraded.
Write-Host "Upgrading PowerShell ${CurrentVersion} to version ${UpgradeVersion}"
## Install the package
If ( $FileType -ieq "MSU" ) { Start-Process wusa.exe -ArgumentList "${File} /quiet /norestart" -Wait }
If ( $FileType -ieq "MSI" ) { Start-Process msiexec.exe -ArgumentList "/i ${File} /qn /norestart" -Wait }
## Delete the downloaded package
Remove-Item -Path $File -Force
}
} Else { Write-Host "This script cannot upgrade PowerShell on this endpoint." }