?
Solved

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

Posted on 2016-11-17
4
Medium Priority
?
85 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 5

Accepted Solution

by:
Kundan Gupta earned 2000 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 14

Expert Comment

by:Ajit Singh
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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
Uncontrolled local administrators groups within any organization pose a huge security risk. Because these groups are locally managed it becomes difficult to audit and maintain them.
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Suggested Courses

770 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