I have run into a bit of very repeatable (at least in the environment here at work) behavior in a little script I threw together and have not been able to find any articles discussing it, nor have I been able to figure out why it is behaving this way, so I
wanted to share it here and see if anyone might know?
The behavior I am getting is that the first/[0] element in the $groupList array is always returning no results. My experiments have shown the following:
1. It is always $groupList[0] (or the first element in the list when I try to use a comma delimited scheme) that returns empty.
2. If I stop the debugger at the Get-ADGroupMember step and manually run the command against the [0] element, it returns a proper value. Then, when I step over, it returns nothing.
3. The other [1]+ indexes always return proper values, despite order changes and index additions/deletions.
4. I have attempted both a full "For" loop and the "ForEach" that is in the example. They both fail in the same way.
5. When I copy the contents of the first array into a second array, then Write-Host on the second array, it works (this is the code that works) -- Note: There are several formatting additions to this bit that I don't believe are relevant to the
behavior, but am including them for completeness.
I am hoping the behavior repeats in other environments and that someone out there might be able to explain why it is doing this. Thank you for your time!