- Part 1: Deploy your Function to Azure
- Part 2: Create a Custom Connector
- Part 3: Use PowerShell in a PowerApp
Last time, we deployed a function to Azure.
We now have a PowerShell script sitting in the cloud which we can talk to via a HTTP REST call.
This time, we’ll create a Custom Connector in PowerApps so that we can hook our script into an app.
Part 2: Create a Custom Connector
You should first make sure that you can talk to your function with PowerShell:
- Open your Function in the Azure console and click Get function URL.
- Leave default (Function key) selected and copy the URL. You should get something like this:
https://dan-function.azurewebsites.net/api/a_HelloWorld?code=PA1Twlk/anVrchlbKSZSvZcWQCawE5MjY2JcQ3s0/kMYqpnvI2WEMA== - Append &Name=myName to the end and run with Invoke-RestMethod:
Invoke-RestMethod "https://dan-function.azurewebsites.net/api/a_HelloWorld?code=PA1Twlk/anVrchlbKSZSvZcWQCawE5MjY2JcQ3s0/kMYqpnvI2WEMA==&Name=Dan"
Once you’re happy that your function is working, switch over to Power Apps.
Here’s a video demo:
And here are step-by-step instructions:
Start with Custom Connectors → New custom connector → Create from blank
(Create from Azure Service (Preview) doesn’t work with the Azure Functions 2.x runtime – a to-be-expected example of two preview features not working together.)
- General screen
Host is your Azure Functions domain, in my case:
dan-function.azurewebsites.net - Security
Authentication type: API key
Parameter code: code
Parameter label: code
Parameter location: Query - Definition
Action → New action- General
Summary and Operation ID: hello_world - Request
click Import from sample
Verb = POST
URL = an example of a full query, including Name=myName
Click Import, then delete the block named code, as it is already handled in the Security section. - Response
Click Add default response, then run a chunk of PowerShell like this to get an example response that you can paste into the Body field:
- General
$response = Invoke-WebRequest "https://dan-function.azurewebsites.net/api/a_HelloWorld?code=PA1Twlk/anVrchlbKSZSvZcWQCawE5MjY2JcQ3s0/kMYqpnvI2WEMA==&Name=Dan"
# Show response in console
$response
# Copy response body to clipboard
$response.Content | clip
Now save your connector and go to the Test tab.
Under Connections, click New connection. Enter your function key when prompted (the long bunch of characters that appear after code= in a request URL).
When your connection has been created, return to the Test screen, and try out your function. You should hopefully see a familiar and reassuring block of JSON – greetings!
That’s it for now. Next time, we complete the package by adding our PowerShell function to a real life actual PowerApp.