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
{{ message }}
Repository navigation
Connect-Graph : Authentication needed when call is within a function #124
Welcome To Microsoft Graph!
Get-MgUser_List:
Line |
8 | Get-MgUser -Top 1
| ~~~~~~~~~~~~~~~~~
| Authentication needed, call Connect-Graph.
I can reproduce this Error in PS 5.1 and in PS7. I also tried different ways of installing and importing the Graph Module (Global), without improvement.
I can add to this and say I have the same behavior.
Some things to note. If I don't give it a -TenantId, I will get the prompt to do a devicelogin, even if called within a function. However, this context isn't persisted and all further mg functions fail. I have to login from an interactive prompt as stated for the context to be preserved.
If I do specify a -TenantId, I don't even get the devicelogin prompt, it just outputs "Welcome to Microsoft Graph!" (if I pipe to Write-Host in the script), and no context actually gets captured.
Activity
bodangly commentedon Apr 4, 2020
I can add to this and say I have the same behavior.
Some things to note. If I don't give it a -TenantId, I will get the prompt to do a devicelogin, even if called within a function. However, this context isn't persisted and all further mg functions fail. I have to login from an interactive prompt as stated for the context to be preserved.
If I do specify a -TenantId, I don't even get the devicelogin prompt, it just outputs "Welcome to Microsoft Graph!" (if I pipe to Write-Host in the script), and no context actually gets captured.