Install AzureAD and AzureADPreview module in PowerShell Function App

This post has been republished via RSS; it originally appeared at: New blog articles in Microsoft Tech Community.

One wants to install AzureAD and AzureADPreview in his/her windows PowerShell function app. Modules are already input in requirements.psd1managedDependency is also enabled in host.json. But when executing functions in Azure, error "Could not load file or assembly…" shows up.

 

Analysis:

The problem is rooted in the compatibility issue between PS7(PowerShell Core 7) and module AzureAD and AzureADPreview.

 

As of now, the Functions runtime with PowerShell 7 is being rolled out globally. If one wants to check the powershell Core Version, he/she can simply goes to Function Portal --> Configuration --> General settings.

Linru_Hui_0-1628846374887.png

 

 

AzureAD works out of the box with Powershell 7! People need to import AzureAD with the -UseWindowsPowershell switch.

 

 

Import-Module AzureAD -UseWindowsPowerShell

 

 

 

 

Below is the detailed step one can use in order to install AzureAD and  AzureADPreview module in Azure Function App.

Step 1: In requirements.psd1, input the two modules with their versions, wildcard is recommend to get the latest version of module;

 

 

@{ # For latest supported version, go to 'https://www.powershellgallery.com/packages/Az'. # To use the Az module in your function app, please uncomment the line below. # 'Az' = '6.*' 'AzureADPreview' = '2.*' 'AzureAD' = '2.*' }

 

 

 

 

Step 2: make sure “managedDependency” is set to true in host.json;

 

 

{ "version": "2.0", "logging": { "applicationInsights": { "samplingSettings": { "isEnabled": true, "excludedTypes": "Request" } } }, "extensionBundle": { "id": "Microsoft.Azure.Functions.ExtensionBundle", "version": "[1.*, 2.0.0)" }, "managedDependency": { "enabled": true } }

 

 

 

 

Step 3: import module with below syntax:

 

 

Import-Module AzureAD -UseWindowsPowerShell Import-Module AzureADPreview -UseWindowsPowerShell

 

 

 

Results:

Modules will be presented under C:\home\data\ManagedDependencies\xxxxxx.r. One can also invoke methods this module provides in his function code.

 

Linru_Hui_0-1628849096770.png

 

 

 

REMEMBER: these articles are REPUBLISHED. Your best bet to get a reply is to follow the link at the top of the post to the ORIGINAL post! BUT you're more than welcome to start discussions here:

This site uses Akismet to reduce spam. Learn how your comment data is processed.