Forum Discussion
ADumith
Apr 19, 2023Iron Contributor
How to list the disabled accounts and in which groups they are.
Hello guys, I have the following script, my goal is to list all user accounts that are not enabled and in which group they are. Get-ADUSer -SearchBase "DC=mydomain,DC=net" -Filter {enabled -eq ...
- 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
ADumith
Apr 19, 2023Iron Contributor
Hello,
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,
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-Bohren
Apr 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.- Apr 20, 2023Export-CSV -Path "C:\DisabledUsers.csv" -NoTypeInformation