PowerShell: Disable all Outlook add-ins except for a specific list.

I’m currently troubleshooting some Outlook add-in issues, and I needed to disable all Outlook add-ins except for a select few that I needed to stay enabled. Here’s a cut-down version of how I achieved it.

This sample doesn’t contain any error handling or logging code, so please test thoroughly, and remove the –WhatIf switch from line 22 only when you’ve tested it thoroughly.

This script needs to be run as an admin – for example as a computer login script.

# List of add-in names that ARE permitted. Everything else will be disabled
$permittedAddIns = "Redemption.Addin","WorkSiteEmailManagement.Connect","imFileSite.Connect"
# Registry paths to search
$registryPaths = "Registry::HKEY_USERS\S-1-5-21-*\Software\Microsoft\Office\Outlook\Addins",
"Registry::HKEY_USERS\S-1-5-21-*\Software\Wow6432Node\Microsoft\Office\Outlook\Addins",
"HKLM:\Software\Wow6432Node\Microsoft\Office\Outlook\Addins",
"HKLM:\Software\Microsoft\Office\Outlook\Addins"
# Build up a list of add-ins by searching the specified paths
$addIns += ($registryPaths | ForEach-Object {Get-Item $_ | Get-ChildItem | Where-Object Filter {($_.GetValue("LoadBehavior") -and $_.GetValue("LoadBehavior") -ne 0)}})
# Narrow down our list of add-ins to only those that don't match our permitted list
$deniedAddIns = $addIns | ? {$_.PSChildName -notin $permittedAddIns}
# Loop through all of the denied add-ins, and set the LoadBehavior
foreach ($addin in $deniedAddIns) {
# If the current add-in's LB is already set to 0. Skip this one.
if ($addin.GetValue("LoadBehavior") -eq 0) { continue }
# Set the LoadBehavior to zero
Set-ItemProperty Path "Registry::$($addin.Name)" Name "LoadBehavior" Value 0 WhatIf
}