I have two variables; $test and $accounts[0].upn
Both are Strings, both contain the exact same value.
When I run:
Get-ADUser -Filter "UserPrincipalName -eq '$test'"
I get the result I want, however when I run:
Get-ADUser -Filter "UserPrincipalName -eq '$accounts[0].upn'"
It does not return any result.
I get that $accounts is an array, but I thought I should get the same result given the variables are both of same type and value.
See my screenshot below a better understanding of what I am trying to achieve, I only made the $test variable for debugging and I would like the command to work with $accounts[0].upn. Apologies I had to black out some personal information for privacy reasons, it shouldn't hinder understanding the screenshot.
Any help is much appreciated!