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:
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:
$response = Invoke-WebRequest "https://dan-function.azurewebsites.net/api/a_HelloWorld?code=PA1Twlk/anVrchlbKSZSvZcWQCawE5MjY2JcQ3s0/kMYqpnvI2WEMA==&Name=Dan"
# Show response in console
# 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.