- 21 Aug 2024
- 2 Minutes to read
- Print
- DarkLight
- PDF
Get-MSGraphAccessToken
- Updated on 21 Aug 2024
- 2 Minutes to read
- Print
- DarkLight
- PDF
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.
| Parameter | Value |
|---|---|
| Required | true |
| Position | 1 |
| Required | true |
| Default Value | None |
| Accept pipeline input? | true (ByPropertyName) |
| Accept wildcard characters? | false |
-MSClientSecret <String>
The MS client secret for the application granted access to Azure AD.
| Parameter | Value |
|---|---|
| Required | false |
| Position | 2 |
| Required | false |
| Default Value | None |
| Accept pipeline input? | true (ByPropertyName) |
| Accept wildcard characters? | false |
-MSTenantID <String>
The MS tenant ID for the O365 customer granted access to Azure AD.
| Parameter | Value |
|---|---|
| Required | true |
| Position | 3 |
| Required | true |
| Default Value | None |
| Accept pipeline input? | true (ByPropertyName) |
| Accept wildcard characters? | false |
-N10Cert <SwitchParameter>
| Parameter | Value |
|---|---|
| Required | false |
| Position | named |
| Required | false |
| Default Value | False |
| 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
| Parameter | Value |
|---|---|
| Required | false |
| Position | 4 |
| Required | false |
| Default Value | None |
| 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
| Parameter | Value |
|---|---|
| Required | false |
| Position | 5 |
| Required | false |
| Default Value | None |
| 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
| Parameter | Value |
|---|---|
| Required | false |
| Position | 6 |
| Required | false |
| Default Value | None |
| 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.
| Parameter | Value |
|---|---|
| Required | false |
| Position | 7 |
| Required | false |
| Default Value | CurrentUser |
| Accept pipeline input? | false |
| Accept wildcard characters? | false |