I'm having some trouble with a workflow to move User Objects that are returned in a Search activity.
We provision all our users to a Staging OU while we wait for AD to Sync to Azure. I have a workflow on when their AzureObjectID attribute updates from the backsync which then configures the account.
Occasionally A user gets the ObjectID but runs in to issues configuring the EXO mailbox, etc... so i flag those accounts for processing by a separate workflow that runs on a schedule. I'm struggling with this scheduled worklflow moving the AD object at the end.
The WF does a Search and gets a list of the user objects that need to be moved. This works just fine.
Inside the search activity I have an activity that runs a powershell script to configure their mailbox and some other items. This works fine.
After that finishes, i need to move them to a calculated OU based on their Office attribute. This part does not seem to work. I use the Move Object activity, it gets the correct Target which is the "Found Object". In the Destination Container I have it run a script and this is where I run in to issues. I need to get the object's GUID to look up a handful of attributes. I am trying to use this but it does not seem to work: [guid]$ObjectGuid = $Workflow.FoundObject("Search").Get("ObjectGuid")
I use that same code in my PS Script which is in the same activity and it works.
Here is my function. It's got a lot of extra slop from me trying to troubleshoot this. I suspect I'm just misunderstanding something fundamental or the Move Object activity just isn't supporting $Workflow.FoundObject.
function MoveUserToFacilityOUWF ($Workflow) { #This function will return the OU that the user object should be moved to. $ProvConfig = Import-LocalizedData -BaseDirectory 'D:\Scripts\functions' -FileName UHS-ARSConfigurations.psd1 $LogFile = $ProvConfig.LogLocation + '\MessagingConfigurations.txt' Get-ChildItem -Path "D:\Scripts\Functions\*.ps1" | % { . $_.FullName } $StepInfo = Get-ProvisioningStep -StepId 1014 Import-Module sqlserver "MoveUserToFacilityOUWF" | Out-File $LogFile -Append [guid]$ObjectGuid = $Workflow.FoundObject("Search").Get("ObjectGuid") try { $UserInfo = Get-ADUser -Identity $ObjectGuid -Properties EmployeeNumber, extensionattribute12 $LawsonLocationCode = $UserInfo.extensionAttribute12 } catch { "[MoveUsertoFacilityOUWF] Could not get extensionAttribute12 for moving user to their facility OU" | Out-File $LogFile -Append $UserInfo.SamAccountName | Out-File $LogFile -Append } "Facility: " + $LawsonLocationCode | Out-File $LogFile -Append if ($LawsonLocationCode) { $NewOU = GetUserFinalOU -LawsonLocationCode $LawsonLocationCode "moveto: " + $NewOU | Out-File $LogFile -Append return $NewOU } else { $UserInfo.SamAccountName + "cannot be moved due to missing extensionAttribute12 (LocatCode) attribute. Please review and move account." | Out-File $LogFile -Append #throw "$($UserInfo.SamAccountName) has no extensionAttribute12 to look up facility OU" } }