Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Flow - Move user to AD OU

matt_a
Kilo Guru

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

1 ACCEPTED SOLUTION

DanielCordick
Mega Patron
Mega Patron

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 🙂 

View solution in original post

14 REPLIES 14

A screenshot of the action would also be super helpful!

We used oob action 'Update Object OU' to move the users to disabled OU in AD. 

First we used 'Look up user' action in AD using Sam Account Name as the input. 

Second we used 'Update Object OU' 

For inputs: 

1. Object - got the Distinguished Name of the user from the first action. This worked perfectly.

2. OU= whichever OU you want the user to be moved.

 

 

nkarunakar13092_1-1744317701354.png

 

 

 

shloke04
Kilo Patron

Hi,

See below thread and check if that helps you in your requirement:

https://community.servicenow.com/community?id=community_question&sys_id=344cb214db0b2c50fb4ae15b8a961914

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

Saurabh Gupta
Kilo Patron

Hi,

You can use an OOTB action for the same. "Update AD Object OU".

Input is samaccoutname (User ID) and OU path like "OU=Users,OU=San Diego,OU=USSites,DC=snownet,DC=snow,DC=intranet"

find_real_file.png


find_real_file.png

 

If my answer replied your question please mark appropriate response as correct so that the question will appear as resolved for other users who may have a similar question in the future.

Regards,
Saurabh


Thanks and Regards,

Saurabh Gupta

Hi,

If my answer replied your question please mark appropriate response as correct so that the question will appear as resolved for other users who may have a similar question in the future.

Regards,
Saurabh


Thanks and Regards,

Saurabh Gupta