How to pass a variable to -Filter
问题 I have come across a very strange situation in PS. In a script I have, there is a cmdlet ( Get-Mailbox ) which pulls back a few mailboxes and stores them in $mailboxes . I then loop through this as follows to find a matching AD account. foreach ($user in $mailboxes) { Get-ADUser -Filter {UserPrincipalName -eq $user.UserPrincipalName} } When I run this it errors saying that it can't find the property UserPrincipalName on $user . I have debugged the script and tested it thoroughly. At the point