I have been troubleshooting code today and I discovered that this code does not work. I am using a PowerShell pipeline to send an array of distinguished names to search Active Directory for users with a manager.
$managers | Get-ADUser -Filter {manager -eq $_}
However, if I expand the command to this example with a foreach-object
loop and an explicit variable, the code does work.
$managers | %{$manager = $_; Get-ADUser -Filter {manager -eq $manager}}
What part of the source code forces users to write out expressions like this?
I'm not familiar with the source code for Get-ADUser
, but in working with native PSCustomObjects, using the pipeline works as expected in the first example.