We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now

x

How do i set an alias proxyAddresses as the default SMTP.

CFAIT
CFAIT asked
on
Medium Priority
1,364 Views
Last Modified: 2012-05-06
I've searched EE trying to find a vb script that would set the proxyAddresses in a specific OU starting with "vm-" as the primary SMTP address. i've found listing all proxyAddresses, adding an primary proxyAddresses, etc...

Using vb scripts is there a way to search a specific OU to verify if the proxyAddresses starting with "vm-" is set as the primary? And if it's not, it WILL set as the primary SMTP startig with "vm-" as the default SMTP address.

Thanks in advance for any assistance provided.
Comment
Watch Question

Chris DentPowerShell Developer
CERTIFIED EXPERT
Top Expert 2010

Commented:

Easy enough to do, but do bear in mind that the primary will change again unless it agrees with a recipient policy. Or did you want to turn off the attribute that allows the policy to modify it?

Chris

Author

Commented:
Chris,

Thanks for the reply. Once an account is created the Recipient Policies will set the primary SMTP as the display name "jan.doe@ee.com". Once that's done i can create and set any alias (jdoe@ee.com) as the primary and the Recipient Policy will not revert back to jan.doe. So to answer your question it will agree.

~ross
Chris DentPowerShell Developer
CERTIFIED EXPERT
Top Expert 2010

Commented:

Hey Ross,

Good stuff. I'll put something together to deal with this for you. Probably won't be tonight, hope that's not a bother.

Chris

Author

Commented:
Chris,

Any assistance is appreciated, no worries man. I  extremely grateful.

~ross
PowerShell Developer
CERTIFIED EXPERT
Top Expert 2010
Commented:

Apologies for the delay.

If we're just dealing with a single OU, and no sub-folders, then this short VbScript (save as .vbs) should do what we need.

It looks a bit messy, but it does the following:

1. Looks for any user with an SMTP address containing vm-.
2. Checks if that address is Primary or not. If not, it makes the address Primary.
3. Checks the rest of the addresses and removes any other Primary address
4. Echoes the change if there is one (so it's best to run this with cscript.exe)
5. Writes the change to the account

Chris
Set objOU  = GetObject("LDAP://OU=Somewhere,DC=yourdomain,DC=net")
objOU.Filter = Array("user")
 
For Each objUser in objOU
  arrProxyAddresses = objUser.Get("proxyAddresses")
 
  booChanged = False
  For i = 0 To UBound(arrProxyAddresses)
    If InStr(1, arrProxyAddresses(i), "vm-", vbTextCompare) > 0 And _
        Left(arrProxyAddresses(i), 4) = "smtp" And _
        booChanged = False Then
 
      ' Set the new Primary
      arrProxyAddresses(i) = Replace(arrProxyAddresses(i), "smtp:", "SMTP:")
      booChanged = True
 
    ElseIf InStr(1, arrProxyAddresses(i), "vm-", vbTextCompare) = 0 And _
        Left(arrProxyAddresses(i), 4) = "SMTP" And booChanged = True Then
 
      ' Remove the current Primary
      arrProxyAddresses(i) = Replace(arrProxyAddresses(i), "SMTP:", "smtp:")
 
    End If
  Next
 
  If booChanged = True Then
    WScript.Echo objUser.Get("name")
    WScript.Echo Join(arrProxyAddresses, vbCrLf)
 
    objUser.Put "proxyAddresses", arrProxyAddresses
    objUser.SetInfo
  End If
Next

Open in new window

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

Commented:
Chris,

It worked great! It scanned the OU looking for any user having "vm-" as an alias and set it to be the primary SMTP address. However, after setting "vm-" as the primary it doesn't delete the previous proxyAddresses. any thoughts?

Thanks,
Ross
Chris DentPowerShell Developer
CERTIFIED EXPERT
Top Expert 2010

Commented:

You didn't say you wanted it to, or I missed that :)

Would you like it to only leave the vm- address?

Chris

Author

Commented:
Chris,

You're right, i didn't asked for it. I found a way to remove it using ldifde, but if there is a way to only leave "vm-" address that would be helpful.

Thanks,
Ross

Author

Commented:
Chris,

If this is taking too much of your time then i'm sorry. I'll just use ldifde. Thanks again for all your help.

~ross
Chris DentPowerShell Developer
CERTIFIED EXPERT
Top Expert 2010

Commented:

Sorry dude, I just keep losing track.

Here's a bit of a different script that should deal with this one.

Chris
Set objOU  = GetObject("LDAP://OU=Somewhere,DC=yourdomain,DC=net")
objOU.Filter = Array("user")
 
Dim arrNewAddresses()
 
For Each objUser in objOU
  arrProxyAddresses = objUser.GetEx("proxyAddresses")
  booHasAddress = False
 
  ReDim arrNewAddresses(0)
  j = 0
 
  For i = 0 To UBound(arrProxyAddresses)
    If InStr(1, arrProxyAddresses(i), "vm-", vbTextCompare) > 0 And _
        InStr(1, arrProxyAddresses(i), "SMTP", VbTextCompare) > 0 Then
 
      ReDim Preserve arrNewAddresses(j)
      arrNewAddresses(j) = Replace(arrProxyAddresses(i), "smtp:", "SMTP:")
      j = j + 1
      booHasAddress = True
 
    ElseIf InStr(1, arrProxyAddresses(i), "SMTP", VbTextCompare) = 0 Then
 
      ReDim Preserve arrNewAddresses(j)
      arrNewAddresses(j) = arrProxyAddresses(i)
      j = j + 1
    
    End If
  Next
 
  ' Ensure only one address is Primary
 
  booHasPrimary = False
  For i = 0 To UBound(arrNewAddresses)
    If booHasPrimary = True Then
      arrNewAddresses(i) = Replace(arrNewAddresses(i), "SMTP:", "smtp:")
    End If
    If InStr(arrNewAddresses(i), "SMTP:") > 0 Then
      booHasPrimary = True
    End If
  Next
 
  If j > 0 And booHasAddress = True Then
    WScript.Echo objUser.Get("name")
    WScript.Echo Join(arrNewAddresses, vbCrLf)
 
    objUser.Put "proxyAddresses", arrNewAddresses
    objUser.SetInfo
  End If
Next

Open in new window

Author

Commented:
Thanks again!
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.