Home » PowerShell » Export List of Disabled Users from Active Directory

Export List of Disabled Users from Active Directory

We have discussed in previous post about how to check ad user enabled status using Enabled property. If ad user account is disabled, we need to get list of disabled users and export list of disabled users to csv file to take necessary action.

Active Directory user object has Enabled property, if Enabled property value is False, it means account it disabled.

In this article, I will explain how to get list of disabled user in active directory and export list of disabled users from active directory using PowerShell.

In the example given below, we will find disabled users and export list of users to csv file using PowerShell Export-Csv cmdlet.

Export List of Disabled Users from Active Directory

If you want to have list of disabled users in active directory, we need to find all disabled users in active directory.

Using PowerShell Get-ADUser filter * gets all the users and checking each user Enabled property value is True or false to check user disabled status. Run below command

Get-ADUser -Filter * -Property Enabled | Where-Object {$_.Enabled -like "False"} | Select Name,SamAccountName,DistinguishedName,SID | Export-Csv -Path C:\disabledUsers.csv -NoTypeInformation

In the above PowerShell script,

First command gets all users using Get-ADUser cmdlet and pass output to second command.

Second command check ad user enabled status using Where-Object and pass output to third command.

Third command select users Name, SamAccountName, DistinguishedName and SID property and pass disabled users properties to fourth command.

Fourth command uses PowerShell Export-Csv cmdlet to export list of disabled users from active directory to location specified by -Path parameter.

Csv file contains information about disabled users from active directory.

Cool Tip: How to get ad user not logged in x days in PowerShell!

Conclusion

I hope above article helps you to check ad user enabled status and get list of disabled users from active directory. Using PowerShell Export-Csv cmdlet to export list of disabled users from active directory to csv file.

Active directory enabled status helps to identify user account status either active or disabled.

If ad user account is disabled more than X days or using ad user last logon more than X days, you can delete disabled ad account.

You can find more topics about PowerShell Active Directory commands and PowerShell basics on ShellGeek home page.

Leave a Comment