title: Powershell, created user, wanted to create mailbox, but cannot find user in AD
body: <p>I have created a PowerShell script that works great, for most of the times.
  First the script creates a user account. Immediately after that, (after a "read-host "does user need to have a mailbox" input) it creates a mailbox. When it's finished doing that, some (Out of Office) settings are applied to the mailbox. </p>
  
  <p>For some reason, it looks like the script is too fast. Quite often it ends in failure, saying that the user cannot be found. It happens just after the mailbox creation part, when I want to apply some settings.
  If i wait for some minutes between the user creation and mailbox creation part, things go fine.</p>
  
  <p><strong>Code</strong></p>
  
  <pre><code># code here that creates user account.
  # read-host "does user need to have a mailbox"?
  
  Enable-Mailbox -identity $sam -database $maildb
  
  # here I get Enable-Mailbox outputs - Name, Alias etc
  
  Get-Mailbox -identity $sam | Set-Mailbox -ExternalOOFOptions InternalOnly
  </code></pre>
  
  <p>Often, I get the error:</p>
  
  <blockquote>
    <p>Error: Couldn't find object in OU</p>
  </blockquote>
  
  <p>I just want the script to create everything without me having to wait.
  Is there a way that i can accomplish this ?</p>
  
  <p>I'm running the script from a workstation and am importing the active-directory and exchange PowerShell modules.</p>