Link to home
Start Free TrialLog in
Avatar of P S
P S

asked on

Need to move selected user with a specific attribute to an OU from their existing OU

My requirement is to move few users from an OU to a different OU. All users are currently under "SAMPLE" OU and all of them have an attribute "xyz" set with a value '3'.

ex: user "Test" is located in OU=Sample,DC=Contoso,DC=com. He's got an attribute named "xyz" set with value '3'. I would like to move this user to OU=Sample1,DC=Contoso,DC=com

My requirement is to move user accounts with attribute name "xyz" of value 3 from an OU for ex: OU=Sample,DC=COntoso,DC=com to OU=Sapmple1,DC=Contoso,DC=com

Additionally, all those accounts which are supposed to be moved are disabled and i need to enable them as well.

Let me know if any other information is required

Thanks in advance
Avatar of oBdA
oBdA

In test mode; remove the -WhatIf in line 5 to run it for real.
$Attribute = 'xyz'
$Value = 3
$SourceOU = "OU=Sample,DC=Contoso,DC=com"
$TargetOU = "OU=Sample1,DC=Contoso,DC=com"
Get-ADUser -SearchBase $SourceOU -Filter "$Attribute -eq '$Value'" | Move-ADObject -TargetPath $TargetOU -WhatIf

Open in new window

Avatar of P S

ASKER

Thanks oBdA. I'll test the script. Maybe I should have mentioned to move all users from "SAMPLE" OU to "SAMPLE1" only if they are disabled and have an attribute "xyz" set with value "3" and later enable them as well.

Can you add "enable" part to the script?
ASKER CERTIFIED SOLUTION
Avatar of oBdA
oBdA

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of P S

ASKER

Thanks oBdA. This worked perfectly.