# # Read from a group the users you want to change # $g=get-qadgroup -display "Test Mail List" # for ($members=0; $members -le $g.member.count-1 ;$members++) { $b=$g.member[$members] $c=[ADSI]"LDAP://$b" $primarySMTP=$c.mail $email=$c.proxyAddresses $first=[STRING]$c.givenname $last=[STRING]$c.sn $newaddress=[STRING]$first+"."+[STRING]$last+"@Domain.com" $already=get-qaduser -searchroot "ADdomain.com/" -LdapFilter "(proxyaddresses=smtp:$newaddress)" # #Check for a Dup SMTP if not, write a new one, if so Bail # if ($already.dn -eq $null) { "$PrimarySMTP Gets a new Primary SMTP address of $newaddress" #Get All the SMTP Addresses and change the old Primary to a secondary for ($address=0; $address -le $email.count-1 ;$address++) { $email[$address] $text=$email[$address] $up=$text.substring(0,5) #$up if ($up -ceq "SMTP:") { $low=$up.tolower() $oldprimary=$low+$primarySMTP "Primary Address $text has been Changed to $oldprimary" $email[$address] = $oldprimary } } $c.proxyaddresses+="SMTP:"+$newaddress $c.mail=$newaddress $c.setinfo() } Else { $already.name + " already has this Address $primarySMTP" } #$newaddress + $c.mail } "done"