Using AzureAD module requires an awkward workaround
See original GitHub issueI’ve created a powershell function app on a consumption plan and I’m trying to use the AzureAD module in my project. I’m getting this error
Exception: The current processor architecture is: X86. The module 'D:\home\site\wwwroot\Modules\AzureAD\2.0.2.16\AzureAD.psd1' requires the following architecture: Amd64.
I’ve set the platform settings to 64 bit, restarted the app, and ran the following commands in a http trigger
[Environment]::Is64BitProcess
[Environment]::Is64BitOperatingSystem
and got the following output
2019-05-23T20:18:23.336 [Information] OUTPUT: False
2019-05-23T20:18:23.337 [Information] OUTPUT: True
Is there any reason why setting the platform settings to 64 bit would not convert the platform to using a 64 bit process?
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:34 (15 by maintainers)
Top Results From Across the Web
'Connect-AzureAD' is not recognized as a name of a cmdlet
The error message you're encountering is indicating that the AzureAD module is missing a required assembly, System.Windows.Forms, which is ...
Read more >How to fix The term 'Connect-AzureAD' is not recognized
1. Start by running PowerShell as an administrator. · 2. Once PowerShell has opened, use the Install-Module AzureAD cmdlets with the -force parameter....
Read more >Unable to install Azure Active Directory Module for ...
Method 1: Install Azure Active Directory Module for Windows PowerShell when you log on as local admin · Log on as a local...
Read more >O365 refresh token. Copy the 'Application (client) ID and paste it
One is using Azure AD V2 authentication endpoint. The app will request a new login from the user. Microsoft 365: Domain or user...
Read more >The term 'Connect-AzureAD' is not recognized as the name ...
Open PowerShell as an administrator, Enter: Install-Module AzureAD · Confirm the installation by entering “A” – Yes to All.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
For anyone else who may stumble on this. (Until they’ve finished correcting this.) The following finally got things working for me.
Import-Module AzureAD -UseWindowsPowerShell
Thanks all for the feedback. Took me a couple hours to get this working. 😔
Big thanks @AnatoliB!
EDITED:
Import-Function
replaced withImport-Module
, as this was a typo.@abigailbuckholdt I was able to connect to AzureAD via a Powershell Azure Function to get a list of users back. It wasn’t easy, but here are the steps:
As @maertendMSFT mentioned above, there is a secret “preview” AzureAD module available in Azure Cloud Shell today, that’s supported on x86 (since Azure Shell uses PowerShell Core). There’s no way to get the x64 version of AzureAD working on Azure Function, unless Microsoft decides to support that architecture in Azure Function. Thus, we’re going to be waiting until this secret preview module is available for use in Azure Function etc, which obviously will take a lot of time. I decided to get this module out of the Cloud Shell, and import it as a standard module in my function, which is supported today in Azure Function (provided the module works on PowerShell Core of course)
Step 1: Getting that Preview PowerShell module out of Cloud Shell To do this, I first initiated a Cloud Shell instance, which in turn created a File Share. By running the two powershell commands in the screenshot below, you’re able to copy the entire Module Folder from the machine hosting Cloud Shell, and see it in the File Share.
Then, I used Storage Explorer to download it to my local:
Which looked like this:
Step 2: Getting the module uploaded to Azure Function, and getting it to work This part was really, really difficult. The thing is, I’m trying to use a Service Account to automate the task of Connect to Azure AD. But, Connect-AzureAD does not support connecting to a Service Account by using the ClientID and AppKey. You need to use a self-signed Cert and pass in the thumbprint.
This works fine and dandy on my local, but this cert based authentication feature is not supported in this Preview AzureAD (you can try it on Azure Cloud Shell, it’s going to return a .NETCORE error):
So - we now have the preview module that’ll work on Azure Function…but it doesn’t support Cert based authentication with service principals (i.e. it’s useless, since the only reason I’m building the function is to automate stuff)
So, I did a lot of digging around, and am basically doing the following to get this to work:
When you deploy to the function with VSCode, this whole folder will get uploaded to the machine hosting the Azure Function.
Here are all the steps in a screenshot:
Now when I use a REST Client (I use Insomnia) to make a call to the function, I’m getting the first user in my Tenant back, via the AzureAD module:
Hope this helps! Judging by all the technical hurdles Microsoft is going to have to have to overcome (specially supporting the Cert based authentication on an unsupported .NET Core platform), I’m willing to bet it’ll be some time before we see this AzureAD module functionality supported out of the box. None of this would be an issue if instead of Powershell Core, the regular 64-bit version was supported in Azure Function though…