How to get the AD user that was disabled in the past 6 months and also the time stamp when it was disabled in dd/MM/yyyy format as.CSV file?
Like using this Powershell https://learn.microsoft.com/en-us/powershell/module/addsadministration/get-aduser?view=win10-ps ?
$paramhash=@{
UsersOnly = $True
AccountDisabled = $True
SearchBase = "OU=Employees,DC=globomantics,dc=local"
}
Search-ADAccount @paramHash |
Get-ADuser -Properties Description,Department,Title,LastLogonDate,WhenChanged |
sort LastLogonDate |
Select Name,Department,Title,Description,WhenChanged,LastLogonDate,DistinguishedName |
out-gridview -title "Disabled Employees"
Instead of using Out-GridView
to display the results, you need to save them to a file. You can do that easily in the CSV format by using Export-Csv
like this.
Export-Csv '.\DisabledEmployees.csv' -NoTypeInformation
To be clear, just replace the Out-GridView
line at the end of the pipeline with this line.