Install AzureAD and AzureADPreview module in PowerShell Function App
Published Aug 15 2021 06:20 PM 27K Views

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.



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.




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 ''.
    # 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





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






1 Comment
Version history
Last update:
‎Aug 13 2021 03:07 AM
Updated by: