Search code examples
powershellazure-active-directoryazure-functionspowerapps

Azure function app to run get-azuread command


I'm new to Azure functions, but I'd like to create a simple function that runs a get-azuread PowerShell command to return the displayname of a single user through an HTTP response.

The command runs fine in a local PowerShell CLI, but I'm stuck on proper authentication for this function app.

In the end, the call and the result of this function app will come and be pushed towards a PowerApp, which can only be opened by authenticated users.

So in short;

  1. User pushes button in PowerApps
  2. Function app runs get-azuread command
  3. Result returns in PowerApps collection

I've tried searching for examples online, but it seems there are multiple possibilities to tackle this problem and I can't figure out any more what's the best solution for my specific requirement.

You can use self signed certificates? Managed identities? But in the end I already have credentials which are used to open the PowerApps. Can I not use these to continue?


Solution

  • Note:

    You should really be using the MSGraph module or API calls to do this going forward:

    https://learn.microsoft.com/en-us/powershell/microsoftgraph/installation?view=graph-powershell-1.0

    To answer your question however

    I wrote a scaffolded azure function and published it here: https://github.com/brettmillerb/azureadFunction

    The main part is to use the -useWindowsPowerShell switch when importing the module.

    Import-Module AzureAD -UseWindowsPowerShell

    You have to modify the settings to get the function to run as x64 however:

    Setting the application to run as x64 bit:

    Function App > Configuration > General Settings > Platform > 64 Bit