Skip to content

Instantly share code, notes, and snippets.

@jschpp
Last active November 16, 2022 09:21
Show Gist options
  • Save jschpp/68686a6b7bd604b56666 to your computer and use it in GitHub Desktop.
Save jschpp/68686a6b7bd604b56666 to your computer and use it in GitHub Desktop.
Deletes OAB locally and deactivates automatic OAB download for prompted user
# This script remove the local Offline Address Book files and sets the
# registry key to disable automatic download of the OAB
$OFS = "`r`n`r`n"
[System.Reflection.Assembly]::LoadWithPartialName('Microsoft.VisualBasic') | Out-Null
try {
$username = [Microsoft.VisualBasic.Interaction]::InputBox("Input username", "User", "")
$User = New-Object System.Security.Principal.NTAccount($username)
$sid = $User.Translate([System.Security.Principal.SecurityIdentifier]).value
} catch {
[Microsoft.VisualBasic.Interaction]::MsgBox("An Error occured:$OFS$_",0,"Fehler!")| Out-Null
exit
}
$office = [Microsoft.VisualBasic.Interaction]::InputBox("Please enter the Office version.${OFS}Office 2010 -- 14.0${OFS}Office 2013 -- 15.0${OFS}Office 2016 -- 16.0", "Office Version", "15.0")
New-PSDrive HKU Registry HKEY_USERS | Out-Null
New-ItemProperty "HKU:\${sid}\Software\Microsoft\Office\$office\Outlook" -Name "DownloadOAB" -Value 0 -PropertyType "DWord"
$MOABU = Get-ChildItem "HKU:\${sid}\Software\Microsoft\Exchange\Exchange Provider\OABs"
foreach ($oab in $MOABU) {
$oabid = $oab.GetValue("MOABU")
Remove-Item "c:\Users\$username\AppData\Local\Microsoft\Outlook\Offline Address Books\$oabid\*"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment