Hopefully someone can help me out. I am trying to get into a specific Organizational Unit which contains multiple groups and I want to display the ones that has a blank ManageBy
field. The problem I don't know how to overcome mostly is how to get all the groups out of the OU I don't need or want the actual users of the groups just the groups the name of the groups and the ones without a ManageBy
field from that OU. I know how to get groups and show their names by doing.
Get-ADGroup -Filter 'Names "*"'
This would just list all the groups in the whole Active Directory not just the specific OU and I don't know how to filter only the ones that have a blank ManageBy
field. The only thing I can think of for getting the groups with no ManagedBy
is this
Get-ADGroups | Where-Object {$_.ManagedBy -eq $null)
The only other thing I could think of was to create a variable and assign it a specific OU and then get the groups from that variable.
But I don't know if that's even possible to work. I am really new to PowerShell and Active Directory so any help would be great. If someone could help me out with this I would appreciate it.
If you're going to use
Where-Object
, you need to askGet-ADGroup
to return theManagedBy
property by using the-Properties
parameter. Otherwise, it'll always be null.However, if you pipe the results into
Where-Object
, you are asking AD for more than you need. You're getting every group in the OU, then you're discarding some of the results. It'll work, it's just unnecessary traffic.This will ask AD for only what you need: