For example, when our users are terminated, we need to remove all groups. I want to check for groups still connected to user, but not show the users where the groups are removed.
I have the following, which shows all disabled users, but can't figure out how to test for a null group. Any help would be appreciated.
Import-Module Activedirectory
Get-ADUser -Filter 'enabled -eq $false' -Properties DisplayName,memberof | % {
New-Object PSObject -Property @{
UserName = $_.DisplayName
Groups = ($_.memberof | Get-ADGroup | Select -ExpandProperty Name) -join
","}
} | Select UserName,Groups