Now that I know how to handle the SID for existing objects, I'm working on the creation of new objects. I have a script in a business rule that triggers after a user account is created. It provisions the resource account for the mailbox and the GALSync contact. What I'm trying to do is get the SID of the newly created objects, but there seems to be some sort of delay after creating the objects before I can retrieve the SID.
I'm using the following command to create the contact for example.
$newContact = New-AdmObject -Name "%cn%" -Type contact -Path "<OU_DN>" -Server "contact.domain" -PassThru
After this command I get the DistinguishedName, Name, ObjectClass, and ObjectGUID, but the ObjectSID is returned blank. I have tried using the following command, but get an error saying that the object doesn't exist.
$newContact = Get-AdmObject $newContact.distinguishedName -Server "contact.domain" -Properties objectSID
If I add a loop that sleeps until the objectSID is retrieved, it eventually finds the object and returns the value, but I'd like to avoid a long delay if possible.
Perhaps there is a better way to accomplish what I am trying to do. Any suggestions would be greatly appreciated.