Table of Contents
The Property Authority Cannot be Found on this Object
In some cases, when we’re trying to connect to Microsoft Graph PowerShell using the below script.
#Generate Access Token to use in the connection string to MSGraph
$AppId = 'fa09463d-8d14-477c-b92b-3b56406b7c3a'
$TenantId = '09655504-399b-41a5-b5c6-fc98a92bc6d1'
$ClientSecret = 'jbe8Q~mGKViQaH3Usv2xhWL2emnqXXu4KxU.ZalE'
Import-Module MSAL.PS -Force
$MsalToken = Get-MsalToken `
-TenantId $TenantId `
-ClientId $AppId `
-ClientSecret ($ClientSecret | ConvertTo-SecureString -AsPlainText -Force)
#Connect to Graph using access token
Connect-Graph -AccessToken $MsalToken.AccessToken
We got the following error:
The property ‘Authority’ cannot be found on this object. Verify that the property exists.
At C:\Program Files\WindowsPowerShell\Modules\MSAL.PS\4.37.0.0\Get-MsalToken.ps1:338 char:38
+ … TenantId) { [void] $AquireTokenParameters.WithAuthority((‘https://{0} …
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], PropertyNotFoundException
+ FullyQualifiedErrorId : PropertyNotFoundStrict
We check the installed version of the Microsoft Graph PowerShell module on our computer. We’re using the v1 of Microsoft PowerShell SDK module.
Recommend: Update the Graph PowerShell SDK to v2.
PS C:\> Get-InstalledModule Microsoft.Graph | FT -AutoSize
Version Name Repository Description
------- ---- ---------- -----------
1.28.0 Microsoft.Graph PSGallery Microsoft Graph PowerShell module
We discovered that we get this error if we run any of the following commands before running Get-MSALToken. We’re assuming it’s going to be any Graph modules though.
- Select-MgProfile -Name “beta”
- Import-Module Microsoft.Graph.Users
- Import-Module Microsoft.Graph.Identity.Signins
- Import-Module Microsoft.Graph.Authentication
The solution to fix it is quite simple, you just need to add this parameter into the script as follows:
#Generate Access Token to use in the connection string to MSGraph
$AppId = 'fa09463d-8d14-477c-b92b-3b56406b7c3a'
$TenantId = '09655504-399b-41a5-b5c6-fc98a92bc6d1'
$ClientSecret = 'jbe8Q~mGKViQaH3Usv2xhWL2emnqXXu4KxU.ZalE'
Import-Module MSAL.PS -Force
$MsalToken = Get-MsalToken `
-TenantId $TenantId `
-ClientId $AppId `
-ClientSecret ($ClientSecret | ConvertTo-SecureString -AsPlainText -Force) `
-AzureCloudInstance 1
#Connect to Graph using access token
Connect-Graph -AccessToken $MsalToken.AccessToken
The error should be gone, then you can connect to Microsoft Graph PowerShell API.
PS C:\> Import-Module MSAL.PS -Force
PS C:\> $MsalToken = Get-MsalToken `
>> -TenantId $TenantId `
>> -ClientId $ClientId `
>> -ClientSecret ($ClientSecret | ConvertTo-SecureString -AsPlainText -Force) `
>> -AzureCloudInstance 1
PS C:\> Get-MgContext
ClientId : 87c980ca-a1dd-4748-98db-8007af2bdc70
TenantId : c032627b-6715-4e39-9990-bcf48ee5e0c5
CertificateThumbprint :
Scopes : {User.ReadWrite.All}
AuthType : UserProvidedAccessToken
AuthProviderType : UserProvidedToken
CertificateName :
Account :
AppName : MrGraph
ContextScope : Process
Certificate :
PSHostVersion : 5.1.22621.1778
Read more: AzureCloudInstance Enum
Not a reader? Watch this related video tutorial: