You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Connect-Graph succeeds, but Get-MgUser reports the following error: Authentication needed, call Connect-Graph.
Exactly the same commands executed interactively on a PowerShell console run successfully, so this does not look like a configuration/environment issue. In order to repro:
Save this code into a test.ps1 file.
IMPORTANT: In a brand new PowerShell session, invoke test.ps1 like this: .\test.ps1 or this: & .\test.ps1. (If you run the Connect-Graph and Get-MgUser commands by invoking these commands one by one in a PowerShell console, or dot-sourcing the same script (. .\test.ps1), these commands succeed and the issue does not repro.)
As a workaround, inserting the following line immediately after Connect-Graph invocation fixes the problem:
$global:GraphAuthConfigId=$GraphAuthConfigId
While debugging this, we noticed that Get-MgUser cannot find the GraphAuthConfigId variable, even though it is definitely initialized by Connect-Graph. We can even print it out from the script scope, and the content looks correct. I suspect the variable is created in a way that makes it invisible in the Get-MgUser function scope, and this is why copying it into the global scope helps. Perhaps this should be fixed in the code that creates the variable.
The text was updated successfully, but these errors were encountered:
Perhaps a PSVariable object should be created with a constructor that takes ScopedItemOptions, passing something like ScopedItemOptions.AllScope. I haven't tried this fix, just an idea.
Uh oh!
There was an error while loading. Please reload this page.
The following script fails:
Connect-Graph
succeeds, butGet-MgUser
reports the following error: Authentication needed, call Connect-Graph.Exactly the same commands executed interactively on a PowerShell console run successfully, so this does not look like a configuration/environment issue. In order to repro:
.\test.ps1
or this:& .\test.ps1
. (If you run theConnect-Graph
andGet-MgUser
commands by invoking these commands one by one in a PowerShell console, or dot-sourcing the same script (. .\test.ps1
), these commands succeed and the issue does not repro.)As a workaround, inserting the following line immediately after Connect-Graph invocation fixes the problem:
While debugging this, we noticed that
Get-MgUser
cannot find theGraphAuthConfigId
variable, even though it is definitely initialized byConnect-Graph
. We can even print it out from the script scope, and the content looks correct. I suspect the variable is created in a way that makes it invisible in theGet-MgUser
function scope, and this is why copying it into the global scope helps. Perhaps this should be fixed in the code that creates the variable.The text was updated successfully, but these errors were encountered: