Create AD Account and Mailbox by Powershell

Dear all,

I have a question about creating AD user and mailbox:

Background:

There're 4 sites in my organization, and 2 DCs in each site. Exchange servers are in site A, the AD administrators work in sites B & C. I wrote a powershell script to help them creating AD users and mailboxes. Parts of the code are listed:

$DC = $env:LOGONSERVER -replace "\\"
New-ADUser @newUser -OtherAttributes @{ pager = $EmployeeID } -Server $DC -ErrorAction Stop
Enable-Mailbox -Identity $samAccountName -Alias $samAccountName -Database $msdb -DomainController $DC

My question:

 Sometimes the mailbox cannot be created, and I get the error: Cannot find an object with identity: 'Sandy.Lorena' under: 'DC=ms,DC=com'

I want to create an AD user, make some settings, and then create a mailbox for this AD user. How should I do if I want to prevent the above error?

Thank you in advance.

July 29th, 2015 10:31pm


 Sometimes the mailbox cannot be created, and I get the error: Cannot find an object with identity: 'Sandy.Lorena' under: 'DC=ms,DC=com'

Greetings,

                  This error occurs when the script searches for the object named  Sandy.Lorena in the domain 'DC=ms,DC=com' and hence inturn unable to create a mailbox and link it. This may occur due to many reasons,

1. Replication Latency.

2. The searchbase used in the script points to a specific location which the object is not located.Please feel free to share the script to check for any errors.

Please confirm which site  the object is created along with the result of the command listed below.

repadmin /showobjmeta <DN of the object> * to check further.

Thanks

Eric

Free Windows Admin Tool Kit Click here and download it now
July 30th, 2015 12:52am

Hi Chenry,

Thanks for your post.

As Eric's suggestion, you could do the troubleshooting for your environment.

Also here is a scripts for create mailboxes and AD accounts from a csv file, you may have a reference.

https://gallery.technet.microsoft.com/scriptcenter/PowerShell-Create-AD-users-97d6ee9c

And for more support, you could also post in the PowerShell forum.

https://social.technet.microsoft.com/Forums/scriptcenter/en-US/home?forum=winserverpowershell

Best Regards,

Mar

July 30th, 2015 1:45am

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

Other recent topics Other recent topics