Organizational Units (OUs) in Active Directory are used to organize users, groups, and other objects based on roles, departments, or similar criteria. Regularly monitoring disabled user accounts within a specific OU helps manage these accounts more effectively. This allows admins to re-enable accounts or remove them to keep the directory secure and organized, with an up-to-date record of account status.
- In the Active Directory Users and Computers console, go to the Filter option in the toolbar.
- Choose the Create custom filter option and click the Customize button.
- Switch to the Advanced tab and enter the following LDAP query, then click OK.
(&(objectCategory=person)(objectClass=user)(userAccountControl:1.2.840.113556.1.4.803:=2))
After completing the above steps , navigate to your OU to view all disabled users within it. However, this approach is limited to displaying disabled users only in the specified OU and does not include users in nested OUs. To view disabled users in nested OUs, PowerShell provides a more comprehensive solution.
Execute the following PowerShell cmdlet to get all disabled users in an OU and from its nested OUs.
Get-ADUser -Filter { Enabled -eq $false } -SearchBase "<OU'sDistinguishedName>" -Properties * |
Select-Object Name, SAMAccountName, UserPrincipalName, DistinguishedName, AccountExpirationDate, LastLogonDate |
Export-Csv -Path "<FilePath>" -NoTypeInformation
Here, replace <OU’sDistinguishedName> with the distinguished name of the OU and <FilePath> with the desired location for your CSV file. To find the distinguished names of all OUs in your organization, use the following command.
Get-ADOrganizationalUnit -Filter * | Select Name, DistinguishedName
Avoid complications with ease! Leverage AdminDroid’s account disabled users report and its rich filtering capability to quickly identify disabled users in a specific OU.