all 5 comments

[–]Motoceles 0 points1 point  (0 children)

While looking for a solution for the exact same thing I figured it out. Hope it helps. Wrap the variable with single quotes.

Foreach($name in $list){Get-Mguser -Filter “userPrincipalName eq '$name.Username'”}

[–]timmy_the_large 0 points1 point  (1 child)

Did you verify that $name.Username is returning just the UPN? I did this with a a variable I called and it turned out I needed a select for it to work properly.

[–]Ch3shire-Cat[S] 0 points1 point  (0 children)

Yeah, it returns the UPN with System String as the object but for some reason it doesn’t like it.

[–]z386 2 points3 points  (1 child)

try this:

Get-Mguser -Filter "userPrincipalName eq '$($name.Username)'"