azurepowershellgithub-actionsazure-ad-b2c

I am not able to import the powershell module Microsoft.Graph.Entra.Beta


I am not able to import the powershell module Microsoft.Graph.Entra.Beta. I want to use Set-EntraBetaTrustFrameworkPolicy module to upload xml configs to Azure AD B2C as per this microsoft doc : https://learn.microsoft.com/en-us/powershell/module/microsoft.graph.entra.beta/set-entrabetatrustframeworkpolicy?view=entra-powershell-beta . And it requires the module Microsoft.Graph.Entra.Beta to be installed.

I am using this commands to install module : Install-Module -Name Microsoft.Graph.Entra.Beta -Scope CurrentUser -Force -AllowClobber

This is the error i see in the github action:

found in any module directory.
At D:\a\_temp\360a07d2-14b9-4abd-8843-bc54622430e9.ps1:22 char:1
+ Import-Module Microsoft.Graph.Entra.Beta
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ResourceUnavailable: (Microsoft.Graph.Entra.Beta:String) [Import-Module], FileNotFoundEx 
   ception
    + FullyQualifiedErrorId : Modules_ModuleNotFound,Microsoft.PowerShell.Commands.ImportModuleCommand```


  [1]: https://learn.microsoft.com/en-us/powershell/module/microsoft.graph.entra.beta/set-entrabetatrustframeworkpolicy?view=entra-powershell-beta



=======================Edit replying to Rukminis question=============
Are you able to do this also? I have created a service principle in Azure AD B2C and want to upload TrustFrameworkExtensions.xml file to it using Set-AzureADMSTrustFrameworkPolicy powershell cmdlet in GHA. Everything in this works for me except the last line . I get an error Set-AzureADMSTrustFrameworkPolicy is not know cmdlet even though I am able to succesfully import Powershell AzureADPreview module without any issues. I am pulling my hair out to figure this out

```Install-Module -Name AzureADPreview -Scope CurrentUser -Force -AllowClobber
az login --service-principal --username $service-principal-clientId --password $service-principal-password --tenant $tenantId --allow-no-subscriptions
$aadToken = az account get-access-token --resource-type aad-graph | ConvertFrom-Json
$graphToken = az account get-access-token --resource-type ms-graph | ConvertFrom-Json
Connect-AzureAD -AadAccessToken $aadToken.accessToken -AccountId $service-principal-clientId -TenantId $tenantId -MsAccessToken $graphToken.accessToken
Set-AzureADMSTrustFrameworkPolicy -Id B2C_1A_TrustFrameworkExtensions -InputFilePath .\Templates\TrustFrameworkExtensions.xml```

Solution

  • To install and import the Microsoft.Graph.Entra.Beta, make use of below yml file:

    name: Azure AD B2C Policy Upload
    
    on:
      push:
        branches:
          - main
    
    jobs:
      install-and-upload:
        runs-on: windows-latest  # Use a Windows runner
        
        steps:
          - name: Checkout code
            uses: actions/checkout@v3  # Checkout your repository code to access the PowerShell script
    
          - name: Install Microsoft.Graph.Entra.Beta module
            shell: pwsh
            run: |
              Install-Module -Name Microsoft.Graph.Entra.Beta -AllowPrerelease -Force -Scope CurrentUser
                       
          - name: Import the module
            shell: pwsh
            run: |
                 Import-Module Microsoft.Graph.Entra.Beta
                 
          - name: Connect the module
            shell: pwsh
            run: |
                 Connect-Entra
    

    enter image description here

    The modules installed and imported successfully like below:

    enter image description here

    The error "Not found in any module directory" usually occurs if there is any issue with PowerShell connection. Make use of shell: pwsh and use the above yml file to install and import modules.