Powershell Automate MG graph Delegated Access

Giri 1 Reputation point


I am looking for a way to Automate certain Tasks using MG Graph, Challenge here is that there is certain permission that requires delegated access. I am not able to get the right article on how to use delegated access without me intervening to enter my username and password Every time.

By Entering Username and password i am able to authenticate and use MG Graph powershell SDK.

i am lost please help here.

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
10,774 questions
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,398 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Vasil Michev 96,516 Reputation points MVP

    Delegate access is by design interactive only, the exception being the ROPC flow. However, once you authenticate, the module will reuse the obtained refresh token and you will no longer see any login prompts, until either the token expires or you manually disconnect. Alternatively, you can authenticate outside of the module and pass a token.

    0 comments No comments

  2. Limitless Technology 39,416 Reputation points

    Hello there,

    This is by design as each API in the Microsoft Graph is protected by one or more permission scopes. The user logging in must consent to one of the required scopes for the APIs you plan to use.

    The Find-MgGraphCommand cmdlet can be used to discover the required permissions for another cmdlet.

    Use the Connect-MgGraph command to sign in with the required scopes. You'll need to sign in with an admin account to consent to the required scopes.

    You can also try App-only authentication with the Microsoft Graph PowerShell SDK


    I hope this information helps. If you have any questions please let me know and I will be glad to help you out.


    --If the reply is helpful, please Upvote and Accept it as an answer--