Morning,
I have a working ‘Update Account’ Function that moves a User to a new OU upon change of a identity attribute. This works fine
I also have a AfterModify Rule that adds/removes a user from groups based upon identity attributes changing. This works fine too.
The problem is that when they combine I’m getting the following error message:
Error processing user : Directory object not found
Basically, the account move is working, but the afterModify is picking up the old DN, and not the new one for the value:
$nativeIdentity = $requestObject.NativeIdentity
Has anyone come this before, and have a solution?
Thanks
I’ve tried adding a 20s wait + loop when I got the error message ‘Directory object not found’
but the following code still doesn’t bring the new native identity: (doesn’t bring anything in, nor run any error messages)
Phil, above nativeidentity object is coming from provisioning plan object and it will not change with updated value even after delay as plan object is constant.
By any chance you have sAMAccountName in provisioning plan?
If not, I would recommend to add sAMAccountName or any other unique identifier/employee number (since this value will not change based on identity attribute change) as an argument via before provisioning and then get this value in after modify script to be used for Get-ADUser command.
Hi Anshu,
I like your thinking, however, there are many articles about why DN has to be the nativeIdentity (regardless how stupid it seems to have a variable rather than a static field as that attribute.
I think I’ve coded my way round it using this:
$nativeIdentity = $requestObject.NativeIdentity
$extensionAttribute1 = Get-AttributeValueFromAccountRequest $requestObject "extensionAttribute1"
if ($null -eq $extensionAttribute1) {
$NativeIdentityNew = $NativeIdentity
}
else {
# Regular expression to match OU='number'
$regex = "OU=\d+"
# Replace the matched part with the new value
$NativeIdentityNew = $NativeIdentity -replace $regex, "OU=$extensionAttribute1"
}
Just a bit more unit testing to do.
EDIT: This works. However, with 4 variables defining the DN, it is going to get ‘clunky’. On my return from AL, I’m going to look at moving all the afterModify changes to a beforeModify as these are group membership only, and then let the OU move happen afterwards. I feel like this should work.