Hi, can anybody help with this plz, im using a PS script to remove disabled users from a specific group, but its not useful when we need to remove them from all groups, i tried to write this but it seems its not working:
Get-ADGroup -Filter 'GroupCategory -eq "Security" -or GroupCategory -eq "Distribution"' -SearchBase "dc=domain,dc=local" | ForEach-Object{ $group = $_
Get-ADGroupMember -Identity $group -Recursive | %{Get-ADUser -Identity $_.distinguishedName -Properties Enabled | ?{$_.Enabled -eq $false}} | ForEach-Object{ $user = $_
$uname = $user.Name
$gname = $group.Name
Write-Host "Removing $uname from $gname" -Foreground Yellow
Remove-ADGroupMember -Identity $group -Member $user -Confirm:$false
}
}
Thanx