Solved

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

Posted on 2016-11-08
4
57 Views
Last Modified: 2016-11-10
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
0
Comment
Question by:A D
  • 2
  • 2
4 Comments
 
LVL 83

Expert Comment

by:oBdA
ID: 41878860
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

0
 

Author Comment

by:A D
ID: 41878867
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?
0
 
LVL 83

Accepted Solution

by:
oBdA earned 500 total points
ID: 41878885
Two "-WhatIf"s now, line 6 and 7. Note that line 7 will now not be executed, because the WhatIf in line 6 doesn't pass anything on. You can just comment out line 6 to verify that it's going to move the correct accounts.
$Attribute = 'Comment'
$Value = 3
$SourceOU = "OU=Sample,DC=Contoso,DC=com" 
 $TargetOU = "OU=Sample1,DC=Contoso,DC=com" 
Get-ADUser -SearchBase $SourceOU -Filter "($Attribute -eq '$Value') -and (Enabled -eq 'False')" |
	Set-ADUser -Enabled $True -PassThru -WhatIf |
	Move-ADObject -TargetPath $TargetOU -WhatIf

Open in new window

0
 

Author Closing Comment

by:A D
ID: 41880306
Thanks oBdA. This worked perfectly.
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Find out how to use Active Directory data for email signature management in Microsoft Exchange and Office 365.
A procedure for exporting installed hotfix details of remote computers using powershell
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles to another domain controller. Log onto the new domain controller with a user account t…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question