Active Directory stores information about users, computers, and other objects in a Windows network. You can use the Get-AdUser cmdlet in PowerShell to get the aduser disabled date.
The Get-AdUser command is used to retrieve the information about users in the Active Directory. The user information includes their displayname, samaccountname, upn, enabled status, whenchanged, etc…
The Get-AdUser has an Enabled
property that contains the boolean value either True or False. The Enabled property indicates whether the user account is enabled or disabled.
The Get-AdUser has a whenChanged
property that contains the date and time that the user account was last changed.
In this article, we will discuss how to get the aduser disabled date in PowerShell using the Get-AdUser command.
How to Get ADUser Disabled Date
Use the Get-AdUser command in PowerShell to get the disabled active directory user and its disabled date.
Get-ADUser -Filter {(Enabled -eq $False)} -Properties Name, whenChanged,Enabled | Select-Object Name, whenChanged,Enabled
In the above PowerShell script, the Get-AdUser cmdlet uses the Filter parameter to specify that only users who are disabled {(Enabled -eq $False)}
should be returned.
The Get-AdUser command uses the Properties
parameter to specify properties that should be displayed for the user object, in this case, it is Name, whenChanged, and Enabled. The whenChanged
property contains the date and time that the user account was last changed. It pipes the list of disabled users to the Select-Object
command.
The Select-Object
command displays the aduser disabled date, name, and enabled status.
The output of the above PowerShell script that returns a list of get aduser disabled is given below.
It displays the user name, Enabled status, and disabled date for the adusers.
You can use the Export-Csv cmdlet in PowerShell to export the active directory users’ information including their disabled date and enabled status in a CSV file. The following command export aduser information to the CSV file.
Get-ADUser -Filter {(Enabled -eq $False)} -Properties Name, whenChanged | Select-Object Name, whenChanged,Enabled | Export-Csv -Path C:\PowerShell\adusers_disabled_date.csv -NoTypeInformation
Cool Tip: How to get adusers from the list in PowerShell!
Conclusion
I hope the above article on how to get aduser disabled date in PowerShell using the Get-AdUser cmdlet is helpful to you.
You can find more topics about PowerShell Active Directory commands and PowerShell basics on the ShellGeek home page.