This script can be used to get a list of all users in a group where the users are contained in a specific OU.
# This script will get all users that are in a specific group under a specific OU.
# As an example, you want to find all users in OU "OU=Users,DC=my,DC=domain,DC=com" that are a member of the group "Some_Group".
$users = Get-ADUser -filter * -SearchBase "OU=Users,DC=my,DC=domain,DC=com" | Select -exp samaccountname
$group = "Some_Group"
$members = Get-ADGroupMember -Identity $group -Recursive | Select -ExpandProperty SamAccountName
ForEach ($user in $users) {
If ($members -contains $user) {
write-host $user
}
}