Solved

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

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

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 10

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

The following article is intended as a guide to using PowerShell as a more versatile and reliable form of application detection in SCCM.
This article outlines the process to identify and resolve account lockout in an Active Directory environment.
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 video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

778 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