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

From MyWiki
Jump to: navigation, search
(Created page with "'''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...")
 
(No difference)

Latest revision as of 09:48, 1 September 2016

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>