Get-MSGraphAccessToken
    • 21 Aug 2024
    • 2 Minutes to read
    • Dark
      Light
    • PDF

    Get-MSGraphAccessToken

    • Dark
      Light
    • PDF

    Article summary

    Get a Microsoft Graph access token for a given MS tenant. Needed to run other Graph API queries.

    Syntax

    Get-MSGraphAccessToken
      -MSClientID  <String>
      -MSClientSecret  <String>
      -MSTenantID  <String>
      -N10Cert
      -CertFriendlyName  <String>
      -CertThumbprint  <String>
      -CertPath  <String>
      -CertStore  <String>
    

    Examples

    Example 1

    $AuthToken = Get-MSGraphAccessToken -MSClientID 41a228ad-db6c-4e4e-4184-6d8a1175a35f -MSClientSecret 43Rk5Xl3K349w-pFf0i_Rt45Qd~ArqkE32. -MSTenantID 17e1e614-8119-48ab-8ba1-6ff1d94a6930
    

    Obtains an authtoken for the given tenant using secret-based auth and saves the results for use in other commands in a variable called $AuthToken

    Example 2

    $AuthToken = Get-MSGraphAccessToken -MSClientID 029834092-234234-234234-23442343 -MSTenantID 234234234-234234-234-23-42342342 -CertFriendlyName 'CertAuth' -CertStore LocalMachine
    

    Obtains an authtoken for the given tenant using certificate auth and saves the results for use in other commands in a variable called $AuthToken

    Parameters

    -MSClientID <String>
    The MS client ID for the application granted access to Azure AD.

    ParameterValue
    Requiredtrue
    Position1
    Requiredtrue
    Default ValueNone
    Accept pipeline input?true (ByPropertyName)
    Accept wildcard characters?false

    -MSClientSecret <String>
    The MS client secret for the application granted access to Azure AD.

    ParameterValue
    Requiredfalse
    Position2
    Requiredfalse
    Default ValueNone
    Accept pipeline input?true (ByPropertyName)
    Accept wildcard characters?false

    -MSTenantID <String>
    The MS tenant ID for the O365 customer granted access to Azure AD.

    ParameterValue
    Requiredtrue
    Position3
    Requiredtrue
    Default ValueNone
    Accept pipeline input?true (ByPropertyName)
    Accept wildcard characters?false

    -N10Cert <SwitchParameter>

    ParameterValue
    Requiredfalse
    Positionnamed
    Requiredfalse
    Default ValueFalse
    Accept pipeline input?false
    Accept wildcard characters?false

    -CertFriendlyName <String>
    The friendly name of an installed certificate to be used for certificate authentication. Can be used instead of MSClientSecret

    ParameterValue
    Requiredfalse
    Position4
    Requiredfalse
    Default ValueNone
    Accept pipeline input?false
    Accept wildcard characters?false

    -CertThumbprint <String>
    The thumbprint of an installed certificate to be used for certificate authentication. Can be used instead of MSClientSecret

    ParameterValue
    Requiredfalse
    Position5
    Requiredfalse
    Default ValueNone
    Accept pipeline input?false
    Accept wildcard characters?false

    -CertPath <String>
    The path to a PFX certificate to be used for certificate authentication. Can be used instead of MSClientSecret

    ParameterValue
    Requiredfalse
    Position6
    Requiredfalse
    Default ValueNone
    Accept pipeline input?false
    Accept wildcard characters?false

    -CertStore <String>
    The certificate store to be used for certificate authentication. Select either LocalMachine or CurrentUser. Used in conjunction with CertThumbprint or CertFriendlyName
    Can be used instead of MSClientSecret.

    ParameterValue
    Requiredfalse
    Position7
    Requiredfalse
    Default ValueCurrentUser
    Accept pipeline input?false
    Accept wildcard characters?false

    Was this article helpful?

    Changing your password will log you out immediately. Use the new password to log back in.
    First name must have atleast 2 characters. Numbers and special characters are not allowed.
    Last name must have atleast 1 characters. Numbers and special characters are not allowed.
    Enter a valid email
    Enter a valid password
    Your profile has been successfully updated.
    ESC

    Eddy AI, facilitating knowledge discovery through conversational intelligence