Remove a proxy email address from select users

The following script will search all users specified and remove email addresses in a specific domain. I have successfully tested it in my domain, to only have Exchange RUS add it back in. Good enough for now.

This uses the Quest ActiveRoles Powershell add-on to gather the DistinguishedName value for all impacted users. You could read this from a file. Otherwise, this script should work on Exchange 2003 and 2007 mailboxes.

### RemoveSMTP.PS1
### EricWoodford.com
### Remove SMTP email addresses from users
### 1/7/2009

$DeadDomain = "example.com"
$users = get-qaduser -Searchroot "TestUsers"

$users
ForEach ($U in $Users) {
        $mdn = $u.dn
        $mldapStr = "LDAP://"+$mdn
        $mldap = [adsi]$mldapstr
        $pa = $mldap.proxyaddresses
        "Before: "+$U.displayname
        $pa
        $BlankAddr = @()
        ForEach ($addr in $PA) {
                If ($addr -notmatch $DeadDomain ) {
                        $blankaddr += $addr
                }
        }
        "After:"
        if ($pa -eq $blankaddr) {
                " -> no change"
        } else {       
                $blankaddr
                $mldap.proxyaddresses = $blankaddr
                $mldap.setinfo()
        }
}

Comments

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <blockquote> <center> <hr> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <img>
  • Lines and paragraphs break automatically.
  • Web page addresses and e-mail addresses turn into links automatically.
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <drupal6>, <html>, <java>, <javascript>, <php>, <posh>.

More information about formatting options

Type the characters you see in this picture. (verify using audio)
Type the characters you see in the picture above; if you can't read them, submit the form and a new image will be generated. Not case sensitive.