One wants to install AzureAD and AzureADPreview in his/her windows PowerShell function app. Modules are already input in requirements.psd1, managedDependency is also enabled in host.json. But when executing functions in Azure, error "Could not load file or assembly…" shows up.
The problem is rooted in the compatibility issue between PS7(PowerShell Core 7) and module AzureADand 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.
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;