soMuch2Learn
soMuch2Learn

Reputation: 187

list of users that are in an OU AND a memberOf a certain sec group

I have 2 lists, one that has all members of a certain OU. Another that lists all the Members of a sec group. I'd like to compare the two lists and compile one list of users that are in both. Anyone nudge me in the right direction?

get-adgroupmember [sec group] | FT Name | out-file "path\file.csv"
get-aduser -filter * searchbase "Conical path of OU" | FT Name | out-file "path\file.csv"

Throwing these two commands into variables[arrays] and using the compare-object really doesn't tell me much. This is a snippet of output from that

InputObject SideIndicator ------------- Microsoft.PowerShell.Commands.Internal.Format.FormatStartData == Microsoft.PowerShell.Commands.Internal.Format.GroupStartData == Microsoft.PowerShell.Commands.Internal.Format.FormatEntryData == Microsoft.PowerShell.Commands.Internal.Format.FormatEntryData == Microsoft.PowerShell.Commands.Internal.Format.FormatEntryData == Microsoft.PowerShell.Commands.Internal.Format.FormatEntryData == Microsoft.PowerShell.Commands.Internal.Format.FormatEntryData == Microsoft.PowerShell.Commands.Internal.Format.FormatEntryData == Microsoft.PowerShell.Commands.Internal.Format.FormatEntryData == Microsoft.PowerShell.Commands.Internal.Format.FormatEntryData == Microsoft.PowerShell.Commands.Internal.Format.FormatEntryData ==

Upvotes: 0

Views: 382

Answers (1)

mjolinor
mjolinor

Reputation: 68341

You shouldn't need that second search at all. The OU location of the users is implicit in their distinguished names:

$ou = 'ou=Execs,ou=Operations,dc=domain,dc=tld'

get-adgroupmember [sec group] |
 where $_.distinguishedname -like "*$ou"

Upvotes: 1

Related Questions