PowerShell returning null values when code is in a script format

$User = Get-MGUser | Where-Object UserPrincipalName -eq $UserPrincipalName

This works perfectly - I connect to Microsoft Graph and can run this. But when I run this in my script - it returns a null value?

I connect to microsoft graph and UserPrincipalName is a valid variable with a valid UPN.

What gives?

This is so weird - when I call variables in my script
Example $myvar | select-object *

I see nothing. Like it’s null ?

Disregard I’m using Invoke-Command so it’s probably looking for variables I’ve not yet defined in the remote session…

Check out this documentation, specifically the ‘using’ variable.

Will do! Thank you :slight_smile: