I have had this issue a long time, whenever I presume that it's going to output all data it does not.
Example:
$groups = "group1","Group2","Group3" # to be excluded
foreach ($group in $groups) {
$dns = (Get-ADGroup "$Group").DistinguishedName
}
Write-Host $dns
will output only one group's distinguished name, but if at the same time I output
(Get-ADGroup "$Group").DistinguishedName | Out-File c:\list.txt
I will get all 3. The same goes with `Get-ADUser, if I try to get user from an array.
Any real solution anyone has come accross?