One-time authentication for microsoft graph powershell sdk

Abhishek Goyal 246 Reputation points

Situation: When i want to connect with cmdlet "Connect-MgGraph" non-interactively I have two option:

  • Use certificate
  • Use Secret'

But, both are expired after a time limit(max 24 months).

So, I just want to know that, Is there something by which I can Connect-MgGraph without further changes like (change secret or certificate).

Can I refresh secret value?

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
10,009 questions
0 comments No comments
{count} votes

Accepted answer
  1. CarlZhao-MSFT 35,101 Reputation points

    Hi @Abhishek Goyal

    You can use Azure AD PowerShell to renew client secrets, there is no maximum, and you can set any date.

    1.Install the Azure Active Directory PowerShell module.

    Install-Module -Name AzureAD

    2.Connect to Azure AD and sign in as an administrator.


    3.Run the script to create a client secret for your app with a 10-year lifetime.

    # Parameters
    $AppObjectID = "{object id of the app}"
    $AppSecretDescription = "Renew Client Secret"
    $AppYears = "10"
    # Add App Client Secret - Valid for 10 years (change to 999 for unlimited years)
    $StartDate = Get-Date
    $EndDate = $StartDate.AddYears($AppYears)
    $AppClientSecret = New-AzureADApplicationPasswordCredential -ObjectId $AppObjectID -StartDate $StartDate -EndDate $EndDate -CustomKeyIdentifier $AppSecretDescription
    # Write Client Secret value
    Write-Host $AppClientSecret.Value

    User's image

    Go to the Azure AD portal and refresh the browser page, you will be able to see the client secret with an expiration date of 2033.

    User's image

    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful