Solved

Need a script to get all the disabled accounts in an OU

Posted on 2016-11-17
4
51 Views
Last Modified: 2016-12-01
I need a powershell script to get details of all disabled accounts in an OU. OU name is Test

OU=Test,DC=Contoso,DC=COM

Can someone help?.

Thanks in advance.
0
Comment
Question by:A D
4 Comments
 
LVL 7

Expert Comment

by:Andy
ID: 41892559
Hi,

Try this command in Powershell:

Search-ADAccount -AccountDisabled
or
Search-ADAccount -AccountDisabled | Select-Object Name

or for OU specific:
Get-ADUser -filter * | where { $_.enabled -eq $False} -SearchBase "OU=ouname, OU=ouname,DC=name,dc=name"
1
 
LVL 3

Accepted Solution

by:
Kundan Gupta earned 500 total points
ID: 41892582
Can be done  with below native powershell cmdlets:

import-module activedirectory
Get-ADUser -Filter * -SearchBase "OU=Test,DC=domain,DC=com" -Properties Name, sAMAccountName, Enabled | ? {$_Enabled -eq $false} | select Name, sAMAccountName, Enabled | Export-csv "c:\disabledusers.csv" -NoTypeInformation
0
 
LVL 9

Expert Comment

by:Kevin k
ID: 41892721
You could try below powershell cmdlets:

Get-ADUser -Filter * -SearchBase "OU=OUName,OU=OUName,DC=name,DC=name" -Properties EmployeeNumber | Where-Object {$_.Enabled -eq $false} | Select-Object SAMAccountName,EmployeeNumber | Export-Csv -Path C:\disabled.csv -NoTypeInformation

Open in new window


This expression will search the entire domain for user accounts that are disabled. The result will be a user account object.
search-adaccount -UsersOnly –AccountDisabled

Open in new window


Here is an article to manage disabled or inactive Active Directory accounts using PowerShell.

search-adaccount -UsersOnly –AccountDisabled –searchbase "OU=employees,dc=globomantics,dc=local"/code>

Open in new window


Import-Module ActiveDirectory
Search-ADAccount  -SearchBase "OU=TestOU,DC=TestDomain,DC=Local" –AccountDisabled -UsersOnly |
 Select -Property Name,DistinguishedName

Open in new window


Export Disabled AD Users to CSV using Powershell:

Import-Module ActiveDirectory
Search-ADAccount –AccountDisabled -UsersOnly |
 Select -Property Name,DistinguishedName |
 Export-CSV "C:\\DisabledADUsers.csv" -NoTypeInformation -Encoding UTF8

Open in new window


Hope this helps!
0
 

Author Closing Comment

by:A D
ID: 41908552
Worked perfectly
0

Featured Post

Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

Question has a verified solution.

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

I thought I'd write this up for anyone who has a request to create an anonymous whistle-blower-type submission form created using SharePoint 2010 (this would probably work the same for 2013). It's not 100% fool-proof but it's as close as you can get…
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 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 …
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 …

912 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

18 Experts available now in Live!

Get 1:1 Help Now