diff --git a/RemoveWindowsAi.ps1 b/RemoveWindowsAi.ps1 index 1cb88b6..ca237a1 100644 --- a/RemoveWindowsAi.ps1 +++ b/RemoveWindowsAi.ps1 @@ -275,29 +275,36 @@ function Disable-Registry-Keys { #powershell core bug where json that has empty strings will error $jsonContent = (Get-Content $config).Replace('""', '"_empty"') | ConvertFrom-Json - if (($jsonContent.browser | Get-Member -MemberType NoteProperty enabled_labs_experiments) -eq $null) { - $jsonContent.browser | Add-Member -MemberType NoteProperty -Name enabled_labs_experiments -Value @() - } - $flags = @( - 'edge-copilot-mode@2', - 'edge-ntp-composer@2', #disables the copilot search in new tab page - 'edge-compose@2' #disables the ai writing help - ) - if ($revert) { - $jsonContent.browser.enabled_labs_experiments = $jsonContent.browser.enabled_labs_experiments | Where-Object { $_ -notin $flags } - } - else { - foreach ($flag in $flags) { - if ($jsonContent.browser.enabled_labs_experiments -notcontains $flag) { - $jsonContent.browser.enabled_labs_experiments += $flag + try { + if (($jsonContent.browser | Get-Member -MemberType NoteProperty enabled_labs_experiments -ErrorAction Stop) -eq $null) { + $jsonContent.browser | Add-Member -MemberType NoteProperty -Name enabled_labs_experiments -Value @() + } + $flags = @( + 'edge-copilot-mode@2', + 'edge-ntp-composer@2', #disables the copilot search in new tab page + 'edge-compose@2' #disables the ai writing help + ) + if ($revert) { + $jsonContent.browser.enabled_labs_experiments = $jsonContent.browser.enabled_labs_experiments | Where-Object { $_ -notin $flags } + } + else { + foreach ($flag in $flags) { + if ($jsonContent.browser.enabled_labs_experiments -notcontains $flag) { + $jsonContent.browser.enabled_labs_experiments += $flag + } } } + + $newContent = $jsonContent | ConvertTo-Json -Compress -Depth 10 + #add back the empty strings + $newContent = $newContent.replace('"_empty"', '""') + Set-Content $config -Value $newContent -Encoding UTF8 -Force + } + catch { + Write-Status -msg 'Edge Browser has never been opened on this machine unable to set flags...' -errorOutput $true + Write-Status -msg 'Open Edge once and run this tweak again' -errorOutput $true } - $newContent = $jsonContent | ConvertTo-Json -Compress -Depth 10 - #add back the empty strings - $newContent = $newContent.replace('"_empty"', '""') - Set-Content $config -Value $newContent -Encoding UTF8 -Force } #disable office ai with group policy