If I have the below code, I find that Powershell doesnt seem to wait until the Get-ADGroupMember has finished.
$Groups = "Group1", "Group2"
foreach ($Group in $Groups) {
Get-ADGroupMember -Identity $Group -Recursive | Select Name
Write-Host "End of line"
}
From the above I would Expect to get the following (Considering my groups have the same users):
Mike Myers
Tim Sanders
Lucy Gray
End of line
Mike Myers
Tim Sanders
Lucy Gray
End of line
But instead I get:
End of line
Mike Myers
Tim Sanders
Lucy Gray
Mike Myers
Tim Sanders
Lucy Gray
End of line