Solved

Powershell: Move all disabled AD accounts to "Ex Employees" OU

Posted on 2013-01-21
5
914 Views
Last Modified: 2013-01-22
Can someone please help. I need to find all disabled user accounts and move them to a specified OU called "Ex Employees" using Powershell.

It would be great if the domain name and OU had a variable so I can use this in multiple environments easily.

THanks!

A.
0
Comment
Question by:Angeal
  • 2
  • 2
5 Comments
 
LVL 35

Expert Comment

by:Joseph Daly
ID: 38802047
This is very simple using the quest cmdlets.

Get-qaduser -disabled | move-qadobject -NewParentContainer {distinguished name of EX employees ou}
0
 

Author Comment

by:Angeal
ID: 38802126
Xxdcmast,

I would prefer to use the builtin AD cmdlets, if possible.

Thanks!

A.
0
 
LVL 40

Accepted Solution

by:
Subsun earned 500 total points
ID: 38802214
Following powershell command Works on Server 2008 R2 domain controllers..
Import-Module ActiveDirectory
Get-ADUser -LDAPFilter {(useraccountcontrol:1.2.840.113556.1.4.803:=2)} | Move-ADObject -targetpath 'OU=Ex Employees,DC=Domain,DC=Com'

Open in new window


Edit : Add -SearchBase if you want to search based on OU's..
Import-Module ActiveDirectory
Get-ADUser -LDAPFilter {(useraccountcontrol:1.2.840.113556.1.4.803:=2)} -SearchBase "OU=Emp,DC=Domain,DC=Com" | Move-ADObject -targetpath 'OU=Ex Employees,DC=Domain,DC=Com'

Open in new window

0
 

Author Comment

by:Angeal
ID: 38805845
Hi Subsun,

Works like a charm! Thanks for your help!.

A.
0
 
LVL 40

Expert Comment

by:Subsun
ID: 38805874
You're Welcome!!
0

Join & Write a Comment

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.
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
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 from a Windows Server 2008 domain controller to a Windows Server 2012 domain controlle…
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…

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

13 Experts available now in Live!

Get 1:1 Help Now