Find all users that have a proxyAddresses entries starting with ":" and then remove the whole string.

From MyWiki
Revision as of 09:48, 1 September 2016 by George2 (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

The Challenge Find all users that have a proxyAddresses entries starting with ":" and then remove the whole string. Ensure the code works with v2 of PowerShell.

The Solution

$users = Get-ADUser -Filter {ProxyAddresses -like ":*"} -Properties ProxyAddresses
 
if ($users) {
foreach ($user in $users) {
$OddProxies = $user.ProxyAddresses | where-object {$_ -like ":*"}
foreach ($OddProxy in $OddProxies) {
Set-ADUser -Identity $user -Remove @{ProxyAddresses = "$($OddProxy)"}
}
}
}
</powershell>