This one goes in the category of a ‘nice & clean’ environment, specifically your Active Directory.
1 |
Get-ADGroup -Filter {GroupCategory -eq 'Security'} | Where-Object {@(Get-ADGroupMember $_).Length -eq 0} |
And to just get the names, simply pipe it to Select-Object and only select the ‘Name’ property.
1 |
Get-ADGroup -Filter {GroupCategory -eq 'Security'} | Where-Object {@(Get-ADGroupMember $_).Length -eq 0} | Select-Object -Property Name |
Note: Go through the list before you’ll delete them. There may be default groups in there aswell as the groups may be in use in other products. So: Think before you act!
Hi Jeff,
A fellow PowerShell person helped me when your command above timed out on me. He suggested a different approach
Get-ADGroup -Filter { GroupCategory -eq ‘Security’ -and member -notlike ‘*’ }
Hi Ronnie,
That would be a better approach indeed. Using a Filter parameter is always best, since it avoids using the pipeline (slow) 😀
Jeff.