From 1aeedfc5c4d9f3e616142f061643a59dfc3bcb4a Mon Sep 17 00:00:00 2001 From: zoicware <118035521+zoicware@users.noreply.github.com> Date: Thu, 5 Dec 2024 16:36:52 -0500 Subject: [PATCH] Disable CoPilot Policies in Region JSON --- RemoveAi.ps1 | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/RemoveAi.ps1 b/RemoveAi.ps1 index 07be224..227f699 100644 --- a/RemoveAi.ps1 +++ b/RemoveAi.ps1 @@ -115,9 +115,39 @@ $provisioned = get-appxprovisionedpackage -online $appxpackage = get-appxpackage -allusers $eol = @() $store = 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Appx\AppxAllUserStore' -$users = @('S-1-5-18'); if (test-path $store) { $users += $((Get-ChildItem $store -ea 0 | Where-Object { $_ -like '*S-1-5-21*' }).PSChildName) } +$packageState = 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Appx\PackageState' +$users = @('S-1-5-18'); if (test-path $store) { $users += $((Get-ChildItem $packageState -ea 0 | Where-Object { $_ -like '*S-1-5-21*' }).PSChildName) } + + +#disable copilot policies in region policy json +$JSONPath = "$env:windir\System32\IntegratedServicesRegionPolicySet.json" +if (Test-Path $JSONPath) { + Write-Host 'Disabling CoPilot Policies in ' -NoNewline + Write-Host "[$JSONPath]" -ForegroundColor Yellow + + #takeownership + takeown /f $JSONPath *>$null + icacls $JSONPath /grant administrators:F /t *>$null + + #edit the content + $jsonContent = Get-Content $JSONPath | ConvertFrom-Json + try { + $copilotPolicies = $jsonContent.policies | Where-Object { $_.'$comment' -like '*CoPilot*' } + foreach ($policies in $copilotPolicies) { + $policies.defaultState = 'disabled' + } + $newJSONContent = $jsonContent | ConvertTo-Json -Depth 100 + Set-Content $JSONPath -Value $newJSONContent -Force + Write-Host "$($copilotPolicies.count) CoPilot Policies Disabled" + } + catch { + Write-Warning 'CoPilot Not Found in IntegratedServicesRegionPolicySet' + } + + +} + -#uninstall packages #use eol trick to uninstall some locked packages foreach ($choice in $aipackages) {