When you’re making changes to your active directory or exchange environment with powershell, it’s a piece of cake with Windows 2008 R2 and/or Exchange 2010. All the cmdlets are there by default.
But when you’re dealing with Windows 2003 and/or Exchange 2003, it’s a whole different story.
I will be posting some of my scripts for Windows 2003 and Exchange 2003 from now on.
Because Windows 2003 has no active directory powershell module, i’m using the Quest AD Templates for that purpose (highly recommended!).
Here’s how to change the primary address for an exchange 2003 user:
function set_exchange2003_primary_address($username, $primary_smtp_address) { # lowercase the to-be-added address $primary_smtp_address = $primary_smtp_address.ToLower() # get current addresses $userinfo = get-qaduser -identity $username $new_proxyaddresses = $userinfo.ProxyAddresses # lowercase all the "SMTP:" entries foreach ($number in 0..($new_proxyaddresses.Count - 1) ) { $address = $new_proxyaddresses[$number] $new_proxyaddresses[$number]=$address.Replace("SMTP:", "smtp:") } # Next, check if the to-be-added address is allready in the list $allready_in_list = $FALSE foreach ($number in 0..($new_proxyaddresses.Count - 1) ) { $address = $new_proxyaddresses[$number].ToLower() $check = $address.CompareTo("smtp:$primary_smtp_address") if ($check -eq 0) { # address is found in the list. Make it PRIMARY $new_proxyaddresses[$number]=$address.Replace("smtp:", "SMTP:") $allready_in_list = $TRUE } } # But if it's not found, add the new adress to the list as primary if ($allready_in_list -eq $FALSE) { $new_proxyaddresses += 'SMTP:'+$primary_smtp_address } # now write the addresses to active directory set-qaduser -identity $username -objectAttributes @{ProxyAddresses=$new_proxyaddresses} }
Hmm..
Guess I should have payed more attention… Why not do this:
function set_exchange2003_primary_address($username, $primary_smtp_address) { get-qaduser -identity $username | Add-QADProxyAddress -Address $primary_smtp_address -Primary }