From 7064a1d6e526cd775e2ccab01b5f8f6e25fd8153 Mon Sep 17 00:00:00 2001 From: David <7734808+Daviid-P@users.noreply.github.com> Date: Tue, 13 Jan 2026 11:31:02 +0100 Subject: [PATCH 1/3] Remove the ability to use Powershell 7 (Core) If it's not going to be supported it's better to block users from even trying to launch the script. --- RemoveWindowsAi.ps1 | 44 ++++++++++++++++++++++++++++---------------- 1 file changed, 28 insertions(+), 16 deletions(-) diff --git a/RemoveWindowsAi.ps1 b/RemoveWindowsAi.ps1 index fbfc407..a98cba2 100644 --- a/RemoveWindowsAi.ps1 +++ b/RemoveWindowsAi.ps1 @@ -27,6 +27,32 @@ if ($nonInteractive) { } +#get powershell version to ensure run-trusted doesnt enter an infinite loop +$version = $PSVersionTable.PSVersion +if ($version -like '7*') { + $Global:psversion = 7 +} +else { + $Global:psversion = 5 +} + +if ($psversion -ge 7) { + Write-Host "ERROR: This script requires Windows PowerShell 5.1 (powershell.exe)." -ForegroundColor Red + Write-Host "You are currently running PowerShell version $($PSVersionTable.PSVersion.Major).$($PSVersionTable.PSVersion.Minor)." -ForegroundColor Red + Write-Host "PowerShell 7+ (pwsh.exe) is not supported. Please run the script using the classic Windows PowerShell 5.1." -ForegroundColor Red + if (-not $nonInteractive) { + try { + Add-Type -AssemblyName System.Windows.Forms + [System.Windows.Forms.MessageBox]::Show( + "This script must be run in Windows PowerShell 5.1.`n`nCurrent version: $($PSVersionTable.PSVersion)`n`nPlease use powershell.exe instead of pwsh.exe.", + "PowerShell Version Error", + [System.Windows.Forms.MessageBoxButtons]::OK, + [System.Windows.Forms.MessageBoxIcon]::Error + ) | Out-Null + } catch { } + } + exit 1 +} If (!([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]'Administrator')) { #leave out the trailing " to add supplied params first @@ -189,12 +215,7 @@ function Run-Trusted([String]$command, $psversion) { # changed start-process to wshell run to avoid the first powershell instance window from flashing - if ($psversion -eq 7) { - $psexe = 'pwsh.exe' - } - else { - $psexe = 'PowerShell.exe' - } + $psexe = 'PowerShell.exe' #convert command to base64 to avoid errors with spaces $bytes = [System.Text.Encoding]::Unicode.GetBytes($command) @@ -264,15 +285,6 @@ function Write-Status { Write-Host '~ ~ ~ Remove Windows AI by @zoicware ~ ~ ~' -ForegroundColor DarkCyan -#get powershell version to ensure run-trusted doesnt enter an infinite loop -$version = $PSVersionTable.PSVersion -if ($version -like '7*') { - $Global:psversion = 7 -} -else { - $Global:psversion = 5 -} - if ($EnableLogging) { $date = (Get-Date).ToString('MM-dd-yyyy-HH:mm') -replace ':' $Global:logPath = "$env:USERPROFILE\RemoveWindowsAI$date.log" @@ -3597,4 +3609,4 @@ if (!$nonInteractive) { $Host.UI.RawUI.ReadKey() *>$null } -exit \ No newline at end of file +exitz From 84a811ed289eba659a89ffe39b15047d68cc2333 Mon Sep 17 00:00:00 2001 From: David <7734808+Daviid-P@users.noreply.github.com> Date: Tue, 13 Jan 2026 11:33:39 +0100 Subject: [PATCH 2/3] Update README with script details and usage instructions --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index e4a5798..905c726 100644 --- a/README.md +++ b/README.md @@ -64,7 +64,7 @@ The current 25H2 build of Windows 11 and future builds will include increasingly --- > [!WARNING] - > Running the script with PowerShell 7 can cause issues, to avoid this ensure you are running Windows PowerShell (5.1) + > Running the script with PowerShell 7 is no longer supported and it WILL cause issues, to avoid this ensure you are running Windows PowerShell (5.1) > ### Launch with UI @@ -196,3 +196,4 @@ If you would like to support my work consider donating :) + From cec746b4bf7115dd84ab41f94568466431f99ad9 Mon Sep 17 00:00:00 2001 From: David <7734808+Daviid-P@users.noreply.github.com> Date: Tue, 13 Jan 2026 11:36:05 +0100 Subject: [PATCH 3/3] Typo --- RemoveWindowsAi.ps1 | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/RemoveWindowsAi.ps1 b/RemoveWindowsAi.ps1 index a98cba2..76a6a5f 100644 --- a/RemoveWindowsAi.ps1 +++ b/RemoveWindowsAi.ps1 @@ -3609,4 +3609,5 @@ if (!$nonInteractive) { $Host.UI.RawUI.ReadKey() *>$null } -exitz +exit +