diff --git a/RemoveWindowsAi.ps1 b/RemoveWindowsAi.ps1 index 110f1e9..cb2b005 100644 --- a/RemoveWindowsAi.ps1 +++ b/RemoveWindowsAi.ps1 @@ -832,47 +832,54 @@ Windows Registry Editor Version 5.00 function Install-NOAIPackage { if (!$revert) { - #check cpu arch - $arm = ((Get-CimInstance -Class Win32_ComputerSystem).SystemType -match 'ARM64') -or ($env:PROCESSOR_ARCHITECTURE -eq 'ARM64') - $arch = if ($arm) { 'arm64' } else { 'amd64' } - #add cert to registry - $certRegPath = 'HKLM:\Software\Microsoft\SystemCertificates\ROOT\Certificates\8A334AA8052DD244A647306A76B8178FA215F344' - if (!(Test-Path "$certRegPath")) { - New-Item -Path $certRegPath -Force | Out-Null - } - - #check if script is being ran locally - if ((Test-Path "$PSScriptRoot\RemoveWindowsAIPackage\amd64") -and (Test-Path "$PSScriptRoot\RemoveWindowsAIPackage\arm64")) { - Write-Status -msg 'RemoveWindowsAI Packages Found Locally...' - - Write-Status -msg 'Installing RemoveWindowsAI Package...' - try { - Add-WindowsPackage -Online -PackagePath "$PSScriptRoot\RemoveWindowsAIPackage\$arch\ZoicwareRemoveWindowsAI-$($arch)1.0.0.0.cab" -NoRestart -IgnoreCheck -ErrorAction Stop - } - catch { - #user is using powershell 7 use dism command as fallback - dism.exe /Online /Add-Package /PackagePath:"$PSScriptRoot\RemoveWindowsAIPackage\$arch\ZoicwareRemoveWindowsAI-$($arch)1.0.0.0.cab" /NoRestart /IgnoreCheck + $package = Get-WindowsPackage -Online | Where-Object { $_.PackageName -like '*zoicware*' } + if (!$package) { + #check cpu arch + $arm = ((Get-CimInstance -Class Win32_ComputerSystem).SystemType -match 'ARM64') -or ($env:PROCESSOR_ARCHITECTURE -eq 'ARM64') + $arch = if ($arm) { 'arm64' } else { 'amd64' } + #add cert to registry + $certRegPath = 'HKLM:\Software\Microsoft\SystemCertificates\ROOT\Certificates\8A334AA8052DD244A647306A76B8178FA215F344' + if (!(Test-Path "$certRegPath")) { + New-Item -Path $certRegPath -Force | Out-Null } + + #check if script is being ran locally + if ((Test-Path "$PSScriptRoot\RemoveWindowsAIPackage\amd64") -and (Test-Path "$PSScriptRoot\RemoveWindowsAIPackage\arm64")) { + Write-Status -msg 'RemoveWindowsAI Packages Found Locally...' + + Write-Status -msg 'Installing RemoveWindowsAI Package...' + try { + Add-WindowsPackage -Online -PackagePath "$PSScriptRoot\RemoveWindowsAIPackage\$arch\ZoicwareRemoveWindowsAI-$($arch)1.0.0.0.cab" -NoRestart -IgnoreCheck -ErrorAction Stop >$null + } + catch { + #user is using powershell 7 use dism command as fallback + dism.exe /Online /Add-Package /PackagePath:"$PSScriptRoot\RemoveWindowsAIPackage\$arch\ZoicwareRemoveWindowsAI-$($arch)1.0.0.0.cab" /NoRestart /IgnoreCheck >$null + } + } + else { + Write-Status -msg 'Downloading RemoveWindowsAI Package From Github...' + $ProgressPreference = 'SilentlyContinue' + try { + Invoke-WebRequest -Uri "https://github.com/zoicware/RemoveWindowsAI/raw/refs/heads/main/RemoveWindowsAIPackage/$arch/ZoicwareRemoveWindowsAI-$($arch)1.0.0.0.cab" -OutFile "$env:TEMP\ZoicwareRemoveWindowsAI-$($arch)1.0.0.0.cab" -UseBasicParsing -ErrorAction Stop + } + catch { + Write-Status -msg "Unable to Download Package at: https://github.com/zoicware/RemoveWindowsAI/raw/refs/heads/main/RemoveWindowsAIPackage/$arch/ZoicwareRemoveWindowsAI-$($arch)1.0.0.0.cab" -errorOutput + return + } + + Write-Status -msg 'Installing RemoveWindowsAI Package...' + try { + Add-WindowsPackage -Online -PackagePath "$env:TEMP\ZoicwareRemoveWindowsAI-$($arch)1.0.0.0.cab" -NoRestart -IgnoreCheck -ErrorAction Stop >$null + } + catch { + dism.exe /Online /Add-Package /PackagePath:"$env:TEMP\ZoicwareRemoveWindowsAI-$($arch)1.0.0.0.cab" /NoRestart /IgnoreCheck >$null + } + } } else { - Write-Status -msg 'Downloading RemoveWindowsAI Package From Github...' - $ProgressPreference = 'SilentlyContinue' - try { - Invoke-WebRequest -Uri "https://github.com/zoicware/RemoveWindowsAI/raw/refs/heads/main/RemoveWindowsAIPackage/$arch/ZoicwareRemoveWindowsAI-$($arch)1.0.0.0.cab" -OutFile "$env:TEMP\ZoicwareRemoveWindowsAI-$($arch)1.0.0.0.cab" -UseBasicParsing -ErrorAction Stop - } - catch { - Write-Status -msg "Unable to Download Package at: https://github.com/zoicware/RemoveWindowsAI/raw/refs/heads/main/RemoveWindowsAIPackage/$arch/ZoicwareRemoveWindowsAI-$($arch)1.0.0.0.cab" -errorOutput - return - } - - Write-Status -msg 'Installing RemoveWindowsAI Package...' - try { - Add-WindowsPackage -Online -PackagePath "$env:TEMP\ZoicwareRemoveWindowsAI-$($arch)1.0.0.0.cab" -NoRestart -IgnoreCheck -ErrorAction Stop - } - catch { - dism.exe /Online /Add-Package /PackagePath:"$env:TEMP\ZoicwareRemoveWindowsAI-$($arch)1.0.0.0.cab" /NoRestart /IgnoreCheck - } + Write-Status -msg 'Update package already installed... Skipping' + #Write-Host $($package | Select-Object *) } } else { @@ -1508,7 +1515,7 @@ function Remove-AI-CBS-Packages { if ($value -ne $null) { if ($value -eq 2 -and $_.PSChildName -like '*AIX*' -or $_.PSChildName -like '*Recall*' -or $_.PSChildName -like '*Copilot*' -or $_.PSChildName -like '*CoreAI*') { Set-ItemProperty "registry::$($_.Name)" -Name Visibility -Value 1 -Force - New-ItemProperty "registry::$($_.Name)" -Name DefVis -PropertyType DWord -Value 2 -Force + New-ItemProperty "registry::$($_.Name)" -Name DefVis -PropertyType DWord -Value 2 -Force | Out-Null Remove-Item "registry::$($_.Name)\Owners" -Force -ErrorAction SilentlyContinue Remove-Item "registry::$($_.Name)\Updates" -Force -ErrorAction SilentlyContinue try {