Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The type initializer for 'Microsoft.Graph.PowerShell.Authentication.Common.ProtectedFileProvider' threw an exception. #4622

Open
jadamones opened this issue Apr 30, 2024 · 1 comment

Comments

@jadamones
Copy link

jadamones commented Apr 30, 2024

Description of the issue

I'm getting the following error when I run an export using a powershell script task in my DevOps pipeline for extracting non-compliant resources. I'm able to do it manually on the agent machine but when it's run through the devops automation pipeline, I'm getting the following. I'm having a tough time figuring out the cause. Any ideas? Also noticed #4491 is having the same issue.

Connect-MgGraph : The type initializer for 'Microsoft.Graph.PowerShell.Authentication.Common.ProtectedFileProvider' 
threw an exception.
At C:\Program Files\WindowsPowerShell\Modules\MSCloudLoginAssistant\1.1.16\Workloads\MicrosoftGraph.psm1:115 char:21
+ ...             Connect-MgGraph -ClientId $Global:MSCloudLoginConnectionP ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Connect-MgGraph], TypeInitializationException
    + FullyQualifiedErrorId : System.TypeInitializationException,Microsoft.Graph.PowerShell.Authentication.Cmdlets.Con 
   nectMgGraph
PowerShell exited with code '1'.

Microsoft 365 DSC Version

V1.24.424.1

Which workloads are affected

Azure Active Directory (Entra ID)

The DSC configuration

# Import the Production configuration file
    $configData = Import-PowerShellDataFile -Path "$workingdirectory\Production\Production.psd1" 

    # Access the NonNodeData section
    $nonNodeData = $configData.NonNodeData

    # Specify the workload
    $workload = 'ReportAutomation'

    # Find credentials for the specified workload
    $workloadCredentials = $nonNodeData.AppCredentials | Where-Object { $_.Workload -eq $workload }

    # Set the Tenant ID
    $TenantId = $nonNodeData.Environment.TenantId
    $DashName = $nonNodeData.Environment.DashName

    # Access the specific values for the Report Automation workload
    if ($workloadCredentials) {
        $ApplicationId = $workloadCredentials.ApplicationId
        $CertificateThumbprint = $workloadCredentials.CertThumbprint
    }
    else {
        Write-Host "No credentials found for workload '$workload'."
    }

    # Export individual policy
    $DateTime = (Get-Date).ToString("yyyy-MM-dd_HH-mm-ss")
    Export-M365DSCConfiguration -Components $array -Path "$workingDirectory" -FileName "$DashName-$DateTime-Export.ps1" -ApplicationId $ApplicationId -CertificateThumbprint $CertificateThumbprint -TenantId $TenantId

Verbose logs showing the problem

Connect-MgGraph : The type initializer for 'Microsoft.Graph.PowerShell.Authentication.Common.ProtectedFileProvider' 
threw an exception.
At C:\Program Files\WindowsPowerShell\Modules\MSCloudLoginAssistant\1.1.16\Workloads\MicrosoftGraph.psm1:115 char:21
+ ...             Connect-MgGraph -ClientId $Global:MSCloudLoginConnectionP ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Connect-MgGraph], TypeInitializationException
    + FullyQualifiedErrorId : System.TypeInitializationException,Microsoft.Graph.PowerShell.Authentication.Cmdlets.Con 
   nectMgGraph
PowerShell exited with code '1'.

Environment Information + PowerShell Version

OsName               : Microsoft Windows 10 Enterprise        
OsOperatingSystemSKU : EnterpriseEdition
OsArchitecture       : 64-bit
WindowsVersion       : 2009
WindowsBuildLabEx    : 19041.1.amd64fre.vb_release.191206-1406
OsLanguage           : en-US
OsMuiLanguages       : {en-US}

Key   : PSVersion
Value : 5.1.19041.4291
Name  : PSVersion

Key   : PSEdition
Value : Desktop
Name  : PSEdition

Key   : PSCompatibleVersions
Value : {1.0, 2.0, 3.0, 4.0...}
Name  : PSCompatibleVersions

Key   : BuildVersion
Value : 10.0.19041.4291
Name  : BuildVersion

Key   : CLRVersion
Value : 4.0.30319.42000
Name  : CLRVersion

Key   : WSManStackVersion
Value : 3.0
Name  : WSManStackVersion

Key   : PSRemotingProtocolVersion
Value : 2.3
Name  : PSRemotingProtocolVersion

Key   : SerializationVersion
Value : 1.1.0.1
Name  : SerializationVersion
@jadamones
Copy link
Author

This only seems to be an issue if I run the export within a the test compliance pipeline. If I run this in a totally separate release pipeline by itself, it will complete. This is an issue though because I need access to output from the test compliance pipeline.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant