cosmo_
cosmo_

Reputation: 11

Get-ADGroup with Where-Object cmdlet

I've been trying to create a script to find a missing "Member of" Group in a Group. Can someone help me write the Where-Object cmdlet because I really don't know how this works.

This is what I already have:

$MissingGroup = "gg-s-MissingGroup"

$Group = Get-ADGroup -Filter 'Name -like "gg-s-*-Group"' -SearchBase "OU=xxxxxxx,DC=xxxxxxxxx,DC=xx" | Format-Table Name

I need the a list of the $Group where the $MissingGroup is NOT a "Member of" it.

Upvotes: 0

Views: 403

Answers (1)

Santiago Squarzon
Santiago Squarzon

Reputation: 60903

You don't need Where-Object for this, you can and should do it with the Active Directory Filter:

$MissingGroup = 'gg-s-MissingGroup'

$getADGroupSplat = @{
    # find all groups where `$MissingGroup` is NOT a member of
    LDAPFilter = '(!memberof={0})' -f (Get-ADGroup $MissingGroup).DistinguishedName
    SearchBase = 'OU=xxxxxxx,DC=xxxxxxxxx,DC=xx'
}

$Group = Get-ADGroup @getADGroupSplat

Upvotes: 2

Related Questions