Pages
  • Homepage
  • Queztaz/Tech Inventory
  • Emacs/EWW Hacks
  • Emacs/Emacs With BiDirectional Google Calendar Sync
  • Emacs/Setting up Mu4e and Multiple Gmail Accounts
  • Linux/Creating an Offline Debian Mirror Repository
  • Linux/Migrate Wiki.js to Another Server
  • Linux/Adding Bitwarden to the Pinephone Pro
  • Linux/Corebooting Thinkpad X220 With CH341A Programmer
  • Pinebook Pro/Custom Kernel
  • Pinebook Pro/Keyboard Firmware Update
  • Pinebook Pro/Netbsd Installation
  • Pinebook Pro/Setting Up Zram
  • Pinebook Troubleshooting/Pro Common Issues
  • Pinebook Pro/Use NVME as Root
  • Pinebook Pro/Write to SPI Flash
  • Qemu/Chroot Into a Different Architecture
  • Qemu/Choot Into an Img File
  • Qemu/Mount Virtual Images
  • Qemu/Windows Xp Fix Smb Not Working
  • Qemu/Windows Xp Installation
  • Misc/Finding the Default Wireless Password to TG1672G Routers
  • Misc/Running Ollama Portably
  • Misc/Resetting Unifi Controller Password with MongoDB CLI
  • Misc/Turning an Amazon FireStick into a Portable Computer
  • Windows/Cloning a Bios Boot Drive to Disimilar Hardware with UEFI
  • Windows/Automatic CHKDSK Scans Using Powershell & Email Alerts
  • Windows/Creating a Decent Portable Terminal
  • Windows/Merging HyperV Snapshots With Powershell
  • Windows/Simulating Bad Blocks on NTFS Filesystems
  • Windows/Creating and Viewing a Storport on Windows Server
  • Windows/Windows 11 PowerShell Upgrade Script
  • Mikrotik/Creating a Client to Site VPN With
  • Mikrotik/Securing Router With Firewall
  • Mikrotik Setup Dynamically Changing IP With No-IP Api
Homepage
  • Homepage
  • Queztaz/Tech Inventory
  • Emacs/EWW Hacks
  • Emacs/Emacs With BiDirectional Google Calendar Sync
  • Emacs/Setting up Mu4e and Multiple Gmail Accounts
  • Linux/Creating an Offline Debian Mirror Repository
  • Linux/Migrate Wiki.js to Another Server
  • Linux/Adding Bitwarden to the Pinephone Pro
  • Linux/Corebooting Thinkpad X220 With CH341A Programmer
  • Pinebook Pro/Custom Kernel
  • Pinebook Pro/Keyboard Firmware Update
  • Pinebook Pro/Netbsd Installation
  • Pinebook Pro/Setting Up Zram
  • Pinebook Troubleshooting/Pro Common Issues
  • Pinebook Pro/Use NVME as Root
  • Pinebook Pro/Write to SPI Flash
  • Qemu/Chroot Into a Different Architecture
  • Qemu/Choot Into an Img File
  • Qemu/Mount Virtual Images
  • Qemu/Windows Xp Fix Smb Not Working
  • Qemu/Windows Xp Installation
  • Misc/Finding the Default Wireless Password to TG1672G Routers
  • Misc/Running Ollama Portably
  • Misc/Resetting Unifi Controller Password with MongoDB CLI
  • Misc/Turning an Amazon FireStick into a Portable Computer
  • Windows/Cloning a Bios Boot Drive to Disimilar Hardware with UEFI
  • Windows/Automatic CHKDSK Scans Using Powershell & Email Alerts
  • Windows/Creating a Decent Portable Terminal
  • Windows/Merging HyperV Snapshots With Powershell
  • Windows/Simulating Bad Blocks on NTFS Filesystems
  • Windows/Creating and Viewing a Storport on Windows Server
  • Windows/Windows 11 PowerShell Upgrade Script
  • Mikrotik/Creating a Client to Site VPN With
  • Mikrotik/Securing Router With Firewall
  • Mikrotik Setup Dynamically Changing IP With No-IP Api

Windows/Windows 11 PowerShell Upgrade Script

Table of content
  • Script Source

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.exe and 7x.dll from C:\Program Files\7-Zip into the same folder as the script

  • Update 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
PREVRANDOMNEXT