Script failing to create mailbox because can’t find account

Hi!

I feel like I have seen this issue on here before, but testing what I thought I had seen as a solution didn’t work for me…

I am running this:

#Create AD User $Parameters = @{ 'SamAccountName' = $UserID 'UserPrincipalName' = "$UserID@domain" 'Name' = “$Displayname” 'GivenName' = $Firstname 'Surname' = $Lastname 'DisplayName' = “$Displayname” 'AccountPassword' = $password 'ChangePasswordAtLogon' = $true 'Enabled' = $false 'Path' = $OUPath 'OfficePhone' = $Telephone 'Office' = $Office 'Description' = $Description 'HomeDrive' = $HomeDrive 'Title' = $Title 'Company' = $Company } New-ADUser @Parameters -credential $MyCredentials #Create Mailbox $Database = get-mailboxdatabase | get-random enable-mailbox -identity $UserID -Database "$Database" 

It happily creates the user but gives an error that it can’t find the user when it goes to enable the mailbox. I tried forcing the domaincontroller it is working on but didn’t resolve:

#Get Domain Controller $DC = Get-ADDomainController -discover -domain my.domain #Create AD User $Parameters = @{ 'SamAccountName' = $UserID 'UserPrincipalName' = "$UserID@domain" 'Name' = “$Displayname” 'GivenName' = $Firstname 'Surname' = $Lastname 'DisplayName' = “$Displayname” 'AccountPassword' = $password 'ChangePasswordAtLogon' = $true 'Enabled' = $false 'Path' = $OUPath 'OfficePhone' = $Telephone 'Office' = $Office 'Description' = $Description 'HomeDrive' = $HomeDrive 'Title' = $Title 'Company' = $Company } New-ADUser -Server $DC @Parameters -credential $MyCredentials #Create Mailbox $Database = get-mailboxdatabase | get-random enable-mailbox -identity $UserID -Database "$Database" -server DC 

Any advice on how i should do this?

submitted by /u/fourpuns
[link] [comments]

Leave a Reply