Getting error “Could not load file or assembly ‘System.Windows.Forms” at ‘Import-Module “AzureAD” line in PS script

Question:

I am trying to deploy a simple powershell function app that contains the following commands:

AzureAD module files have already been copied from local repository “C:\Program Files\WindowsPowerShell\Modules\AzureAD” to “D:\home\site\wwwroot\HttpTrigger1\AzureAD” using KUDU.

Getting error at the Import-Module line, here is the ERROR stack trace:

Answer:

In PowerShell 7, the AzureAD module needs to be explicitly imported with the -UseWindowsPowershell switch, so that it is loaded into a separate Windows PowerShell session:

For more details and caveats, see https://github.com/Azure/azure-functions-powershell-worker/issues/544#issuecomment-702324803

Source:

Getting error “Could not load file or assembly ‘System.Windows.Forms” at ‘Import-Module “AzureAD” line in PS script by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply