Solved

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

Posted on 2016-11-08
4
33 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 82

Expert Comment

by:oBdA
Comment Utility
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
Comment Utility
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 82

Accepted Solution

by:
oBdA earned 500 total points
Comment Utility
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
Comment Utility
Thanks oBdA. This worked perfectly.
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
Find out how to use Active Directory data for email signature management in Microsoft Exchange and Office 365.
This tutorial will walk an individual through the steps necessary to join and promote the first Windows Server 2012 domain controller into an Active Directory environment running on Windows Server 2008. Determine the location of the FSMO roles by lo…
This tutorial will walk an individual through the process of configuring their Windows Server 2012 domain controller to synchronize its time with a trusted, external resource. Use Google, Bing, or other preferred search engine to locate trusted NTP …

744 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now