Sometimes you need to identify which user accounts are disabled in Active Directory, but the Active Directory Users and Computers console isn't ideal for exporting specific values. For instance, you might want to list all disabled users within a particular security group. This is where PowerShell comes in handy, simplifying the process. In this article, you’ll learn how to use PowerShell to export a list of disabled users from Active Directory.
Use this command to retrieve a list of all disabled users in your domain.
Get-ADUser -Filter {(Enabled -eq $False)} -Properties Name, Enabled | select name, enabled
To export all disabled users to CSV use this command.
Get-ADUser -Filter {Enabled -eq $False} -Properties Name, Enabled | Select-Object Name, Enabled | Export-Csv -Path "C:\test\all-disabled-users.csv" -NoTypeInformation
To retrieve a list of disabled users with UPN, LastLogonDate and Surname etc
Get-ADUser -Filter {Enabled -eq $false} -Properties * | Select-Object Name, GivenName, Surname, SamAccountName, UserPrincipalName, DistinguishedName, LastLogonDate
To export the list of disabled users for analysis or reporting
Get-ADUser -Filter {Enabled -eq $false} -Properties * | Select-Object Name, GivenName, Surname, SamAccountName, UserPrincipalName, DistinguishedName, LastLogonDate | Export-Csv -Path "C:\AllDisabledUsers.csv" -NoTypeInformation
To get a list of disabled users from a specific Organizational Unit (OU) in Active Directory, use the following PowerShell command:
Get-ADUser -Filter {Enabled -eq $false} -SearchBase "OU=Sales,DC=test,DC=com" | Select-Object SamAccountName, Name, Enabled | Export-Csv -Path "AllDisabledUsers.csv" -NoTypeInformation
You have now learned how to get a list of disabled users from Active Directory, you've also seen how to use PowerShell commands effectively to manage your directory services. This knowledge will help you streamline administrative tasks and ensure better oversight of user accounts. Keep exploring other PowerShell capabilities to further enhance your Active Directory management skills.