Wanted to pull a list of users who were a part of a certain group last week, but I only wanted the group members that were located in a particular OU in AD. I accomplished this with the following script:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
$strOUDN = "OU=Users,DC=DOMAIN,DC=LOCAL" $arrGroupMembers = Get-ADGroupMember -Identity "GroupName" $arrOUUsers = Get-ADUser -SearchBase $strOUDN -Filter * $arrGroupMemberNames = $arrGroupMembers.Name $arrOUNames = $arrOUUsers.Name foreach($tmpUser in $arrOUNames) { if($arrGroupMemberNames -contains $tmpUser) { Write-Host $tmpUser } } Read-Host "Press Enter to continue" |