• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1263
  • Last Modified:

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

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.
0
CFAIT
Asked:
CFAIT
  • 6
  • 5
1 Solution
 
Chris DentPowerShell DeveloperCommented:

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
0
 
CFAITAuthor 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
0
 
Chris DentPowerShell DeveloperCommented:

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
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
CFAITAuthor Commented:
Chris,

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

~ross
0
 
Chris DentPowerShell DeveloperCommented:

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

0
 
CFAITAuthor 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
0
 
Chris DentPowerShell DeveloperCommented:

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

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

Chris
0
 
CFAITAuthor 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
0
 
CFAITAuthor 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
0
 
Chris DentPowerShell DeveloperCommented:

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

0
 
CFAITAuthor Commented:
Thanks again!
0

Featured Post

[Webinar] Improve your customer journey

A positive customer journey is important in attracting and retaining business. To improve this experience, you can use Google Maps APIs to increase checkout conversions, boost user engagement, and optimize order fulfillment. Learn how in this webinar presented by Dito.

  • 6
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now