Solved

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

Posted on 2016-11-17
4
23 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 6

Expert Comment

by:Andy
Comment Utility
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 2

Accepted Solution

by:
Kundan Gupta earned 500 total points
Comment Utility
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 8

Expert Comment

by:Kevin k
Comment Utility
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
Comment Utility
Worked perfectly
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Disabling the Directory Sync Service Account in Office 365 will stop directory synchronization from working.
Create and license users in Office 365 in bulk based on a CSV file. A step-by-step guide with PowerShell script examples.
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…

763 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

11 Experts available now in Live!

Get 1:1 Help Now