Forum Discussion
How to list the disabled accounts and in which groups they are.
- Apr 19, 2023
The Approach from elieelkarkafi works fine.
$DisabledUsers = Get-ADUser -Filter {(Enabled -eq $false)} -Properties MemberOf | Select-Object Name, MemberOf
Foreach ($User in $DisabledUsers)
{
Write-Host "Username: $($User.Name)"
Foreach ($Group in $user.MemberOf)
{
Write-Host "Group: $Group"
}
}Regards
Andres
Hello elieelkarkafi,
Sorry I forgot to mention that my AD is on-prem, so I wonder this script won't work.
There is a way to pull out only the users that are in any group? because I just realize that the script will provide all the users and I'm looking that thought they are not enabled they are still in some group.
Thank you in advance,
ADumith please use the below script , i added to it to export to csv file
Get-ADUser -Filter {(Enabled -eq $false)} -Properties MemberOf | Select-Object Name, MemberOf | Export-CSV -Path "C:\DisabledUsers.csv" -NoTypeInformation
Please click Mark as Best Response & Like if my post helped you to solve your issue. This will help others to find the correct solution easily.
- ADumithApr 19, 2023Iron ContributorHello,
I think something is wrong because all the user has the same Group which is Microsoft.ActiveDirectory.Management.ADPropertyValueCollection
Any ideas?
Thank you in advance,- Andres-BohrenApr 19, 2023Iron Contributor
The Approach from elieelkarkafi works fine.
$DisabledUsers = Get-ADUser -Filter {(Enabled -eq $false)} -Properties MemberOf | Select-Object Name, MemberOf
Foreach ($User in $DisabledUsers)
{
Write-Host "Username: $($User.Name)"
Foreach ($Group in $user.MemberOf)
{
Write-Host "Group: $Group"
}
}Regards
Andres
- ADumithApr 20, 2023Iron ContributorThank you Andres,
How can I export that into a Excel file?
Thank you in advance.