Script för att hitta medlemmar i distgrupper som ligger i ett specifikt OU

$dist = foreach ($group in (Get-DistributionGroup -Filter {name -like "*"})) {Get-DistributionGroupMember $group | Where-Object {$_.OrganizationalUnit -eq "domain.com/OU/Users/subOU"} | Select @{Label="Group";Expression={$Group.Name}},@{Label="User";Expression={$_.Name}},SamAccountName}
$dist | Sort Group,User

Advertisements