title: Set-ADGroup cannot find group just created in same script (PowerShell)
body: <p>I'm working on a script to create Security and Distribution groups so that they will follow our naming standards.  In the script I use New-DistributionGroup to create the group, Set-DistributionGroup to add some Custom attributes, and then want to use Set-ADGroup to add a Description.  (aside: what a pain that New-DistributionGroup can't do these things!)  Despite setting sleep times up to 30 seconds, Set-ADGroup always fails with:</p>
  
  <blockquote>
    <p>Set-ADGroup : Cannot find an object with identity: '<em>AcctTesting1</em>' under: <em>[our domain]</em>.</p>
  </blockquote>
  
  <p>Yet if I remove the line of code from Set-ADGroup, run the script, and then immediately run the Set-ADGroup code, it works perfectly.</p>
  
  <p>Here is the relevant portion of the script: <em>(our domain name removed)</em></p>
  
  <pre><code>    $GroupTypeName = "Assignment"
      $OU = $BaseOU + "AssignmentGroups"
      New-DistributionGroup -Name $SAMname -Alias $Alias -DisplayName $DisplayName -ManagedBy `
          "CN=Administrator,CN=Users,[our domain]" -OrganizationalUnit $OU `
          -SamAccountName $SAMname -Type Security
      Set-DistributionGroup -Identity $SAMname -CustomAttribute10 "ASSIGNMENT GROUP" `
          -CustomAttribute11 $PRMCode
      echo "Waiting for new group to replicate"
      Start-Sleep -s 20
      Set-ADGroup -Identity $SAMname -Description "$Alias AssignmentGroup"
  </code></pre>
  
  <p>I'm relatively new to PowerShell scripting, so if you have ideas on how to fix this, I'd appreciate a little detail!</p>