jonathanhaddock Posted July 29, 2010 Posted July 29, 2010 Afternoon all, 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 [email protected] * the email address policy, set to "alias@accepteddomain" (so "[email protected]") 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 in advance, Jony
djm968 Posted July 29, 2010 Posted July 29, 2010 You need to modify the Default Recipient Policy, the article linked below should help. Understanding E-Mail Address Policies: Exchange 2010 Help
jonathanhaddock Posted July 29, 2010 Author Posted July 29, 2010 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).
djm968 Posted July 29, 2010 Posted July 29, 2010 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.
jonathanhaddock Posted July 29, 2010 Author Posted July 29, 2010 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! Jonathan
djm968 Posted July 29, 2010 Posted July 29, 2010 (edited) 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. Set-MailUser: Exchange 2010 Help 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. import-csv "c:\aliases\alias.csv"|foreach {set-mailuser -id $_.name -alias $_.alias -verbose -whatif} Edited July 29, 2010 by djm968
jonathanhaddock Posted July 29, 2010 Author Posted July 29, 2010 Hi Again, I'm in the process of writing a script which does what I outlined above, without using Set-MailUser. Running it up in a test environment first - if it works I'll provide a copy...
jonathanhaddock Posted August 2, 2010 Author Posted August 2, 2010 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: # 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 # ([url=http://www.computerperformance.co.uk/powershell/powershell_active_directory.htm]PowerShell - Active Directory LDAP DirectoryServices.DirectoryEntry[/url]) # 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. Thanks for everyone else's help on this!MakeMailboxesForAnOU.txt 1
rh91uk Posted August 3, 2010 Posted August 3, 2010 That might be quick and dirty but it works for us! Thanks so much.
Ric_ Posted August 9, 2010 Posted August 9, 2010 btw... a word of warning... 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!
Ric_ Posted August 9, 2010 Posted August 9, 2010 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
HMCTech Posted August 12, 2010 Posted August 12, 2010 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'
jonathanhaddock Posted August 16, 2010 Author Posted August 16, 2010 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_ Posted August 16, 2010 Posted August 16, 2010 @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!).
jonathanhaddock Posted August 16, 2010 Author Posted August 16, 2010 @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? Jonathan
Ric_ Posted August 16, 2010 Posted August 16, 2010 @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? It was definitely the script that did it - it's not your fault though because there's absolutley no logical reason that the script should have done that. I ran the script on Server 2008 R2 running Exchange 2010 with a domain functional level of 2003 (currently got 1 2003 R2 DC and 1 2008 R2 DC).
jonathanhaddock Posted August 16, 2010 Author Posted August 16, 2010 Hmmm, that's odd but thanks for saying it's not my fault. Unfortunately, I don't have a test environment that mimics what you've got so can't test - might set one up at home to satisfy my curiosity though. I'm guessing the AD recycle bin doesn't work at that functionality level? So you've got: 1x 2008 R2 DC 1x 2003 R2 DC 1x Exchange 2010 server ? When I ran the script there were users that errored if they were disabled or already mail enabled but they definitely still exist here, must be something to do with the combination....
Ric_ Posted August 16, 2010 Posted August 16, 2010 No AD Recylce Bin (I need to replace the 2003 R2 DC and increase the functional level - in hindsight something that I should have done first). Server-wise, I have a lot more than that but they are the relevant ones, yes.
Ric_ Posted August 16, 2010 Posted August 16, 2010 Just had a thought... I also run OCS which might have a bearing on it as it all integrates.
HMCTech Posted August 17, 2010 Posted August 17, 2010 I closed my eyes and let it work on a new OU with users who had no mailbox. It worked out well
Ric_ Posted August 17, 2010 Posted August 17, 2010 I closed my eyes and let it work on a new OU with users who had no mailbox. It worked out well That's what I did... it's all good fun isn't it?!?
jonathanhaddock Posted August 19, 2010 Author Posted August 19, 2010 I've just created 127 new users and run the script against their OU and it still seems fine in my environment. Now slightly paranoid but like Ric_ says, it's not "my fault" so I'm guessing there's a bug in Exchange's powershell somewhere?
JustCrazy Posted May 16, 2011 Posted May 16, 2011 I have seen the code you have done so I was hoping that you could help me I need from the login script the user that is logging in to connect to AD find the upn prefix for the user that is logged in and map a drive to a folder that has the same name as the upn as the user (the user portion of the UPN does not match the samAccountName) as an example samAccountName = JohSmit35 UPN = John Smith Folder Name = John Smith Drive Mapping = H:\users\John Smith
rpwillis Posted January 18, 2012 Posted January 18, 2012 Afternoon all, * the email address policy, set to "alias@accepteddomain" (so "[email protected]") 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) ). To clarify the original problem the default alias has changed in Exchange 2010 to be forenamesurname instead of user principal name.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now