Search existing recipients, if a matching email address is found then randomize the new email address.
Hello all, Ineed toautomate mailbox creation on Exchange 2007 through PowerShell. Does anbody have ideas on how to do the following?1) After taking input from a CSV, create a primaryemail address (ex john.doe@domain)2) Then search through existing recipients for a matching email. If there is a match, append a random 3 digit number to the end (ex john.doe486@domain). I guess that another search would need to be done to ensure this address doesn't exist as well, and continue until no match is found.3) Then, if possible, randomize the mailbox database that it is created on. This is just to evenly spread creation of accounts across all servers and it may not work/be a horrible idea/etc, but I would love to hear ideas on it as well. I know how to handle the CSV, and I found some code that will generate the random number, but that is it. When I tested using New-Mailbox it used the default E-mail Address Policy and it did see the existing email address, and created a similar one, but itappended alphanumeric characters to the end, such as e86e2. I was told that it is not possible to adjust the EAP so it only adds3 numeric digits. Thanks Bill
April 17th, 2009 4:53pm

Hi, I recommend you to export all the user information to csv and then compare it with the csv you created. After that, we may create two import command, one for those new user, another for those existing user. 1. Export exsiting mailbox information to CSV file. Get-MailboxStatistics | select DisplayName, ItemCount, @{expression={$_.totalitemsize.value.ToMB()};name="Size(MB)"}, ServerName, DatabaseName | Export-CSV export.csv 2. Create bulk mailbox via Exchange Management shell. a. Created user.csv file as followsName,Alias,UPNtest,test,test@xyz.com b. Saved file on c: drive c. Ran command below: $Password=Read-Host "Enter Password" -AsSecureString Note: This command will ask you to enter the password for all the mailbox in which is going to be created using csv file d. Ran command below to create mailbox. Import-CSV user.csv | foreach {new-mailbox -alias $_.alias -name $_.name -userPrincipalName $_.UPN -database "Mailbox Database" -org Users -Password $Password}Regards, Xiu
Free Windows Admin Tool Kit Click here and download it now
April 20th, 2009 12:12pm

Xiu, thanks for the reply. I would rather not do a CSV export of existing users. Is there a way to do an LDAP query to Active Directory via PowerShell and verify that the new, proposed, email address does not exist? If it does, then generate a new email and compare via LDAP again.
April 20th, 2009 6:12pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics