Windows/Windows 11 PowerShell Upgrade Script
Table of content
This is a script I wrote to upgrade Windows 10 computers to Windows 11 by downloading an ISO file. It deploys some fixes and checks to increase the success rate of computers upgrading when deployed VIA RMM
Install 7ZIP and copy
7z.exeand7x.dllfromC:\Program Files\7-Zipinto the same folder as the scriptUpdate the URL to the ISO file using the massgrave.dev link in the script comments
Script Source
# Source for direct links: https://massgrave.dev/windows_11_links
# Use that page to replace this one if it breaks
$ISOURL="https://software-static.download.prss.microsoft.com/dbazure/888969d5-f34g-4e03-ac9d-1f9786c66749/26200.6584.250915-1905.25h2_ge_release_svc_refresh_CLIENT_CONSUMER_x64FRE_en-us.iso"
$ProgressPreference="SilentlyContinue"
# https://social.technet.microsoft.com/Forums/windows/en-US/51104081-4ed7-4fdd-8b12-5d1f5be532ae/windows-10-feature-update-via-cmd-powershell-or-gpo
# Exit if not running Windows 10
$WINVER = (Get-CimInstance -ClassName Win32_OperatingSystem).Caption
if ( $WINVER -notlike "*Windows 10*"){
Write-Host "This script only works with Windows 10. Current OSVersion: $WINVER"
Exit 1
}
# Exit if TPM2.0 is not present
$tpm=(Get-WmiObject -Namespace "Root\CIMV2\Security\MicrosoftTpm" -Class Win32_Tpm | select specversion | Select-String "2.0")
if (-not $tpm){
"TPM 2.0 is not available. Please attempt to upgrade manually. Exiting script to prevent hangs"
Exit 1
}
# These folders can cause Windows Updates to fail
Stop-Service -Name wuauserv
Remove-Item 'C:\$Windows.~WS' -Recurse -Force -ErrorAction SilentlyContinue
Remove-Item 'C:\$Windows.~BT' -Recurse -Force -ErrorAction SilentlyContinue
Remove-Item 'C:\$GetCurrent' -Recurse -Force -ErrorAction SilentlyContinue
Start-Service -Name wuauserv
# Restarting the Windows installer Service
Stop-Service -Name msiserver
Start-Service -Name msiserver
# Removing Registry keys that specifically block Windows 11 upgrades
# These keys would have been manually added by a technician
reg DELETE HKLM\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate /v "ProductVersion"/f
reg DELETE HKLM\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate /v "TargetReleaseVersion" /f
reg DELETE HKLM\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate /v "TargetReleaseVersionInfo" /f
reg DELETE HKLM\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate /v "DeferFeatureUpdates" /f
reg DELETE HKLM\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate /v "DeferFeatureUpdatesPeriodInDay" /f
# Clear local group policy
if ($env:ClearLocalGP -eq $true){
Remove-Item "$env:WinDir\System32\GroupPolicyUsers" -Recurse -Force -ErrorAction SilentlyContinue
Remove-Item "$env:WinDir\System32\GroupPolicy" -Recurse -Force -ErrorAction SilentlyContinue
}
# Uninstalls the Windows 10 Update Assistant.
Stop-Process -Name "Windows10UpgraderApp" -Force
Start-Process -FilePath "C:\Program Files (x86)\WindowsInstallationAssistant\Windows10UpgraderApp.exe" -ArgumentList "/forceuninstall" -wait
$dir="C:\Windows\Temp\Windows11UpgradeFiles"
# Downloading the ISO file
Write-Host "Starting upgrade using ISO File"
if (Test-Path -Path "$dir\ExtractedISO") {
Remove-Item -Recurse -Path "$dir\ExtractedISO" -Force
}
mkdir "$dir"
mkdir "$dir\ExtractedISO"
Write-Host "Downloading ISO from $ISOURL"
Invoke-WebRequest -URI "$ISOURL" -OutFile "$dir\Windows11.iso"
Write-Host "Extracting ISO Setup Files"
./7z.exe x "$dir\windows11.iso" -o"$dir\ExtractedISO\"
rm "$dir\Windows11.iso"
Write-Host "Running DISM"
dism /online /cleanup-image /restorehealth
Write-Host "Running SFC"
sfc /scannow
Start-Process -FilePath "$dir\ExtractedISO\setup.exe" -ArgumentList '/Auto Upgrade /DynamicUpdate Disable /Telemetry disable /compat IgnoreWarning /ShowOOBE none /EULA accept' -Wait