Export-M365DSCConfiguration with certificate thumbprint not working
Description of the issue
I have set up an app reg and created and uploaded a cert as per documentation. The problem, however, is that when running Export-M365DSCConfiguration, using certificate thumbprint for authentication, I get an error from Connect-MGGraph:
_Connect-MgGraph : ClientCertificateCredential authentication failed: At C:\Program Files\WindowsPowerShell\Modules\MSCloudLoginAssistant\1.1.39\Workloads\MicrosoftGraph.ps1:130 char:25
- ... Connect-MgGraph -ClientId $Script:MSCloudLoginConnectionP ...
-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~- CategoryInfo : NotSpecified: (:) [Connect-MgGraph], AuthenticationFailedException
- FullyQualifiedErrorId : Microsoft.Graph.PowerShell.Authentication.Cmdlets.ConnectMgGraph_
Trying to run Connect-MGGraph using certificate thumbprint authentication I get the same error if using tenantname.onmicrosoft.com as TenantID. This is expected, because Connect-MGGraph specificly expects the TenantID (e.g. 12345678-1234-abcd-1234567890ab). If I run Connect-MGGraph and provide the actual Tenant ID (not name), then Connect-MGGraph works fine.
The Export-M365DSCConfiguration, however, for some reason expects the TenantID parameter to contain the tenantname.onmicrosoft.com tenant name instead of the actual TenantID. If I run Export-M365DSCConfiguration and try to pass the actual TenantID, it will fail with error: Export-M365DSCConfiguration : Cannot validate argument on parameter 'TenantId'. Please provide the tenant name (e.g., c ontoso.onmicrosoft.com) for TenantId instead of its GUID.
So from what I can see there is a mismatch, where Export-M365DSCConfiguration expects the Tenant name in order to work, but it is then calling Connect-MGGraph and providing that cmdlet with the Tenant name when it should use the TenantID (GUID).
Microsoft 365 DSC Version
1.25.226.1
Which workloads are affected
Office 365 Admin
The DSC configuration
Verbose logs showing the problem
Environment Information + PowerShell Version
OsName : Microsoft Windows Server 2025 Standard
OsOperatingSystemSKU : StandardServerEdition
OsArchitecture : 64-bit
WindowsVersion : 2009
WindowsBuildLabEx : 26100.1.amd64fre.ge_release.240331-1435
OsLanguage : en-US
OsMuiLanguages : {en-US}
Name Value
---- -----
PSVersion 5.1.26100.2161
PSEdition Desktop
Can you update to the latest version 1.25.402.1 and check again there?
Updated to 1.25.402.1. Same error:
_Connect-MgGraph : ClientCertificateCredential authentication failed: At C:\Program Files\WindowsPowerShell\Modules\MSCloudLoginAssistant\1.1.42\Workloads\MicrosoftGraph.ps1:130 char:25
- ... Connect-MgGraph -ClientId $Script:MSCloudLoginConnectionP ...
-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~- CategoryInfo : NotSpecified: (:) [Connect-MgGraph], AuthenticationFailedException
- FullyQualifiedErrorId : Microsoft.Graph.PowerShell.Authentication.Cmdlets.ConnectMgGraph_
That's strange. I can easily authenticate with the following command without errors:
Connect-MgGraph -ApplicationId <clientid> -TenantId tenant.onmicrosoft.com -CertificateThumbprint <thumbprint>
For me, it doesn't matter if the tenant id is the full domain name or just the tenant id. Just to be sure, did you run Update-M365DSCModule to update to the latest version? If you add the -Verbose switch to the export command, what's the full output then?
Edit: I just somehow had this issue, but I was connected in one terminal window and tried the export in another window. After closing all terminal windows and opening just one, it worked.
Oh dear lord, I'm a moron! I kept using a misspelled tenant name all this time! Sorry for wasting your time!
Shit happens, no worries 😄
Still embarrassed about this... You know, when you copy/paste a value in order to avoid misspelling that particular value, and then you find out that the source you copied the value from is misspelled...