
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-09-2022 08:32 AM
Afternoon all, I am trying to move a user to a different active directory OU on the execution of a flow (not workflow).
I can see there is a PSscript: ActionMoveADObjecttoOU.ps1
Has anyone managed to get this working for a user rather than a computer using the AD spoke? And if so, how did you achieve it?
Thanks
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2022 03:55 PM
To get this working i created a custom action using this PS script: In my set up, i have a table with all the OU's I need. then dynamically set it in my flow.
Create an action | ServiceNow Docs
if (test-path env:\SNC_username) {
$UserName = $env:SNC_username;
$OU = $env:SNC_OU;
};
try {
Get-ADUser -Identity "$UserName" | Move-ADObject -TargetPath "$OU"
Write-Host "SUCCESS: Moved $UserName to $OU"
}
catch {
$ErrorMessage = $_.Exception.Message
Write-Host "FAILED to move $UserName to $OU. Error message: $ErrorMessage"
}
Please mark helpful or correct 🙂
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2022 03:55 PM
To get this working i created a custom action using this PS script: In my set up, i have a table with all the OU's I need. then dynamically set it in my flow.
Create an action | ServiceNow Docs
if (test-path env:\SNC_username) {
$UserName = $env:SNC_username;
$OU = $env:SNC_OU;
};
try {
Get-ADUser -Identity "$UserName" | Move-ADObject -TargetPath "$OU"
Write-Host "SUCCESS: Moved $UserName to $OU"
}
catch {
$ErrorMessage = $_.Exception.Message
Write-Host "FAILED to move $UserName to $OU. Error message: $ErrorMessage"
}
Please mark helpful or correct 🙂

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-22-2022 12:37 AM
Worked a treat, thanks for your help Daniel
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-14-2023 10:49 AM
How did you end up importing all of your OUs into ServiceNow? Also any easy way to do any organization when importing?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-14-2023 11:01 AM
Hi,
Type can be "Computer","User","Group", you can remove this filter as well.
$type= $type-replace "%27","'";
$ComputerOUs=Get-ADOrganizationalUnit -Properties CanonicalName -Filter 'Name -like $type' -Credential $cred -Server $computer
foreach($ou in $ComputerOUs)
{
$Name = $ou.distinguishedname
$outdata+=$Name+"|"
}
Write-Host $outdata
Thanks and Regards,
Saurabh Gupta