Quantcast
Channel: Directory Services forum
Viewing all articles
Browse latest Browse all 31638

Create AD Account and Mailbox by Powershell

$
0
0

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.


Viewing all articles
Browse latest Browse all 31638

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>