Internet Related/Filtering/Firewall Thread, Exchange 2010 - mail aliases / email addresses in Technical; Afternoon all,
I'm setting up our new Exchange 2010 server, moving away from Desknow ( DeskNow - Mail and collaboration ...
I'm setting up our new Exchange 2010 server, moving away from Desknow (DeskNow - Mail and collaboration server, hardly anyone's ever heard of it, falls into the "poor" bracket, not my choice gladly). What I'm stumbling on is the email addresses.
My internal domain is of the form bcgs.local, externally that's bartoncourt.org - no problem, I've created an email address policy and set up the accepted domains that covers that. The problem is, the email address the email policy sets up isn't the same as the present email address users expect:
* previously, email addresses were of the form username@bartoncourt.org
* the email address policy, set to "alias@accepteddomain" (so "alias@bartoncourt.org") isn't the same - although alias should equal the username ("By default, this field is populated based on the User logon name (User Principal Name) of the user." (How to Create a Mailbox for a New User: Exchange 2007 Help)
).
So, does anyone know how to fix this frustraing problem? Otherwise I'll end up setting up each account individually just so I can specify the email address (alias) correctly.
Thanks for the reply but unfortunately that's not the answer. This only allows you to base the email addresses on:
%g - Given name (first name)
%i - Middle initial
%s -Surname (last name)
%d - Display name
%m - Exchange alias
%xs - Uses the first x letters of the surname. For example, if x = 2, the first two letters of the surname are used.
%xg - Uses the first x letters of the given name. For example, if x = 2, the first two letters of the given name are used.
I think I'll need to learn PowerShell quickly in order to do this en masse and get this done, looks like exchange doesn't allow you to use username@ by default (which you'd think was an oversight).
Sorry hadn't realised you had already been down that road and I agree this does seem an oversight. So looks like PowerShell is your friend and to be honest I love PowerShell well worth getting to grips and IMO it makes Exchange 2007/2010 Management so much easier.
No worries djm, just slightly depressed that although alias should automatically set to username that it doesn't seem to be. Do you know any good powershell tutorial sites?
I'm thinking my script needs to:
1) Connect to AD
2) From the specified OU, run a for each against all user objects (CN=user) that:
a) finds the upn prefix for the user
b) runs the Enable-Mailbox command with -alias set to the upn prefix
3) Report when complete
Forunately, I have a test domain already for this - just going to be a pita learning power shell in a hurry!
The article linked below is good start, Fortunately PowerShell as its name suggests is a powerful scripting tool and this should be fairly easy to do with one line of code.
I will look though my old scripts, I may have one I wrote for E2K7 which I should work.
Use the Set-MailUser cmdlet to modify the mail-related attributes of an existing user in Active Directory.
Found this PowerShell which you my be able to adapt.
This sets the mailusers' aliases from a CSV. The csv has two fields "name" and "alias" containing the name and the new alias.
Ok, at the risk of sounding presumptuous I'm going to mark this post as the answer. I had to write a powershell script to do this. Naturally I ran it up in a test environment first.
Attached is a txt with the script which is also below:
Code:
# PowerShell find UPN of users in the given OU and create Exchange Mailbox with the alias == UPN
# If the mailbox already exists, the script errors on that entry.
# Author: Jonathan Haddock, following an example PS foreach script from Guy Thomas
# (PowerShell - Active Directory LDAP DirectoryServices.DirectoryEntry)
# Version 1, August 2010, tested with WinSvr 2008 R2 Stnd and Exchange 2010 Stnd
$Dom = 'LDAP://OU=Dummy;OU=Students;OU=User;DC=bcgs;DC=local'
$Root = New-Object DirectoryServices.DirectoryEntry $Dom
$i=0
# Create a selector and start searching from the Root of AD
$selector = New-Object DirectoryServices.DirectorySearcher
$selector.SearchRoot = $root
$adobj= $selector.findall() |`
where {$_.properties.objectcategory -match "CN=Person"}
foreach ($person in $adobj){
$prop=$person.properties
$i++
# In AD the property is userPrincipalName however, PS makes the attribute lower case, hence userprincipalname
$upn = $prop.userprincipalname[0]
# The UPN contains @ followed by the suffix, we only want the UPN prefix so we use split:
$upnsplit = $upn.split("@")
$alias = $upnsplit[0]
# Output the alias to the screen:
Write-host $alias
# Enable the exchange mailbox
Enable-Mailbox -Identity "$upn" -Alias "$alias"
}
"Total $i"
Please note: I take no responsibility for what this script may do to your Exchange 2010 system. I have tested the script and it works fine in my environment but there is no guarantee it will work the same in yours.
I just used the script on an OU containing a dozen or so users and it has made a load of users vanish from AD (or as john put.... "committed murder"). Some of the missing users weren't even in the OU that I used the script on! Most random and most annoying!
It turns out that the script works perfectly if there are no mail-enabled or disabled users in the specified OU. Only then does it go a bit mental and start deleting people in other OUs!
Oh well... it's given me a nice excuse to tidy up the usernames
Would like to use this but a tad worried now about the previous two comments. We have a new year group in an OU to add mailboxes for and also half a dozen new pupils in all 6 other OU's all already full of users with mailboxes.
Will this script work just by setting hte correct OU in $Dom = 'LDAP://OU=Dummy;OU=Students;OU=User;DC=bcgs;DC=local'
The script shouldn't be able to delete anything - there's no delete line in the script anywhere! If it encounters an already email enabled user it errors saying it can't create one but I've not had any users deleted or vanish as a result.
I've run the script on about 10 OUs in my domain and all was successful. If the script encounters a disabled user it won't create the mail box.
@Ric_ - can you confirm the users are definitely gone?
@AlexPilot
That's what I was doing, targeting a single OU at a time...
Jonathan
(sorry for delayed response, was on holiday with no Internet)
@Ric_ - can you confirm the users are definitely gone?
They definitely went!
I cannot work out what happened because I can see that the script should not effect anything but the alias and mail-enabled status... I can only think that it was something to do with either the disabled or mail-enabled accounts as those were the only things that errored. The users that went AWOL were even in different OUs! Random indeed!!!
I have since run the script on 4 other OUs (approx. 450 users) and there hasn't been a problem (touch wood!).
@Ric_
Thanks for the clarification - you certainly had me worried that I'd done something wrong. I appreciate it doesn't help you but I'm happy to say it wasn't the script that did the deed.
Was anything else happening in your domain at the time? What OS and domain/forest functionality level are you on?