How to delete empty OUs through command?

I work in a bank and there are a thousands of users with around thousand OUs so i got task to delete empty OUs but its a lot of OUs so its hard to delete manually one by one so please can anyone tell me powershell command so first i can get list of empty OUs and then delete all empty OUs through one command in powershell ? 

Hope anyone can help me out.

September 14th, 2015 12:50pm

You will need to write a fairly complex script to do this safely.  There is no way to know if an "empty" OU is not longer needed.

You can get all OUs and check for Children.

Get-AdOrganizationalUnit -filter * 

Free Windows Admin Tool Kit Click here and download it now
September 14th, 2015 1:05pm

I work in a bank and there are a thousands of users with around thousand OUs so i got task to delete empty OUs but its a lot of OUs so its hard to delete manually one by one so please can anyone tell me powershell command so first i can get list of empty OUs and then delete all empty OUs through one command in powershell ? 

Hope anyone can help me out.

Get-ADOrganizationalUnit -Filter * | % { if(Get-ADObject -SearchBase $_.distinguishedname -SearchScope onelevel -filter *){"keep $_"}else{"remove $_"}}

input your own code into the script

September 14th, 2015 1:25pm

oh my gosh it looks so hard like making an script. Although we are system engineer not a programmer so making a script is quite difficult will need a lot of time in order to make a script )))):
Free Windows Admin Tool Kit Click here and download it now
September 14th, 2015 1:30pm

I work in a bank and there are a thousands of users with around thousand OUs so i got task to delete empty OUs but its a lot of OUs so its hard to delete manually one by one so please can anyone tell me powershell command so first i can get list of empty OUs and then delete all empty OUs through one command in powershell ? 

Hope anyone can help me out.

Get-ADOrganizationalUnit -Filter * | % { if(Get-ADObject -SearchBase $_.distinguishedname -SearchScope onelevel -filter *){"keep $_"}else{"remove $_"}}

input your own code into the script

September 14th, 2015 1:33pm

oh my gosh it looks so hard like making an script. Although we are system engineer not a programmer so making a script is quite difficult will need a lot of time in order to make a script )))):

You will need to contact a consultant to do this for you.  This si a scripting forum.  It is not a magic shop.  If you do not want to script then try posting in a user forum for AD or looking for third part solutions.

Free Windows Admin Tool Kit Click here and download it now
September 14th, 2015 1:34pm

Okay sir got it , i am in a  wrong forum then..............
September 14th, 2015 2:35pm