-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRemove-NewOutlook.ps1
More file actions
76 lines (66 loc) · 4.55 KB
/
Copy pathRemove-NewOutlook.ps1
File metadata and controls
76 lines (66 loc) · 4.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# removes new outlook for all users and blocks windows from bringing it back
# see https://github.com/mews-se/no-new-outlook for what and why
$ErrorActionPreference = 'Stop'
if ($PSVersionTable.PSEdition -eq 'Core') {
Write-Warning 'The Appx cmdlets are unreliable in PowerShell 7. Run this in Windows PowerShell (powershell.exe).'
exit 1
}
$user = [Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()
if (-not $user.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) {
Write-Warning 'Run this from an elevated PowerShell prompt.'
exit 1
}
function Set-RegDword($path, $name, $value) {
if (-not (Test-Path $path)) { New-Item $path -Force | Out-Null }
Set-ItemProperty $path -Name $name -Value $value -Type DWord
}
# mail and calendar go too: dead since end of 2024, and their migration flow
# installs new outlook through the store, where the deprovision marker can't block it
$apps = 'Microsoft.OutlookForWindows', 'microsoft.windowscommunicationsapps'
Write-Host 'Removing new Outlook and the dead Mail and Calendar apps for all users'
foreach ($app in $apps) {
Get-AppxPackage -AllUsers $app -ErrorAction SilentlyContinue |
Remove-AppxPackage -AllUsers -ErrorAction Continue
}
Write-Host 'Deprovisioning them so Windows Update leaves them out'
Get-AppxProvisionedPackage -Online | Where-Object { $_.DisplayName -in $apps } |
ForEach-Object { Remove-AppxProvisionedPackage -Online -PackageName $_.PackageName -ErrorAction Continue | Out-Null }
# the marker windows honors across feature updates, set even if the package was never provisioned
$depro = 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Appx\AppxAllUserStore\Deprovisioned\Microsoft.OutlookForWindows_8wekyb3d8bbwe'
if (-not (Test-Path $depro)) { New-Item $depro -Force | Out-Null }
Write-Host 'Blocking the update orchestrator installer'
$oobe = 'HKLM:\SOFTWARE\Microsoft\WindowsUpdate\Orchestrator\UScheduler_Oobe'
Remove-Item "$oobe\OutlookUpdate" -Recurse -Force -ErrorAction SilentlyContinue
if (Test-Path $oobe) { Remove-ItemProperty $oobe -Name OutlookUpdate -ErrorAction SilentlyContinue }
if (-not (Test-Path $oobe)) { New-Item $oobe -Force | Out-Null }
# add to the block list without clobbering entries other tools may have put there
$blocked = ([string](Get-ItemProperty $oobe -Name BlockedOobeUpdaters -ErrorAction SilentlyContinue).BlockedOobeUpdaters).Trim()
if ($blocked -notmatch '^\[.+\]$') { $blocked = '["MS_Outlook"]' }
elseif ($blocked -notmatch '"MS_Outlook"') { $blocked = $blocked -replace '\]$', ',"MS_Outlook"]' }
else { $blocked = $null }
if ($blocked) { Set-ItemProperty $oobe -Name BlockedOobeUpdaters -Value $blocked -Type String }
# not in microsoft's docs but community-proven: mark the oobe install job as already done
Set-RegDword 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Orchestrator\UScheduler\OutlookUpdate' workCompleted 1
# per-user settings go into every loaded hive, not just hkcu: elevating from a
# standard account would otherwise land them in the admin's profile
Write-Host 'Telling classic Outlook to stay classic (all logged-in users)'
$sids = (Get-ChildItem Registry::HKEY_USERS | Where-Object { $_.PSChildName -match '^S-1-(5-21|12-1)(-\d+){4}$' }).PSChildName
foreach ($sid in $sids) {
$u = "Registry::HKEY_USERS\$sid"
Set-RegDword "$u\Software\Policies\Microsoft\office\16.0\outlook\preferences" NewOutlookMigrationUserSetting 0
Set-RegDword "$u\Software\Policies\Microsoft\office\16.0\outlook\options\general" DoNewOutlookAutoMigration 0
Set-RegDword "$u\Software\Policies\Microsoft\office\16.0\outlook\options\general" NewOutlookAutoMigrationRetryIntervals 0
Set-RegDword "$u\Software\Policies\Microsoft\office\16.0\outlook\options\general" HideNewOutlookToggle 1
Set-RegDword "$u\Software\Microsoft\Office\16.0\Outlook\Options\General" HideNewOutlookToggle 1
Remove-ItemProperty "$u\Software\Microsoft\Office\16.0\Outlook\Preferences" -Name UseNewOutlook -ErrorAction SilentlyContinue
}
# fail closed: an inventory error here should abort loudly, not pass as "all gone"
$leftover = @(foreach ($app in $apps) { Get-AppxPackage -AllUsers $app }) +
@(Get-AppxProvisionedPackage -Online | Where-Object { $_.DisplayName -in $apps })
if ($leftover) {
Write-Host ''
Write-Warning 'Some packages survived removal, likely because they are in use. Close Outlook and run the script again. The registry blocks are in place either way.'
exit 1
}
Write-Host ''
Write-Host 'Done. Settings were applied to every logged-in user profile; accounts that were not logged in need a later run.'