PowerShell in Azure Functions: Modules and CLI Integration

PowerShell is a powerful scripting language that can be run in an Azure Function Apps. However, working with PowerShell in this environment often requires adding custom modules and enabling command-line tools (CLI). In this post, I’ll walk through multiple approaches for adding PowerShell modules and several ways to integrate CLI tools into your Function App. Before adding any module, it’s important to check whether it’s already loaded and confirm that it’s compatible with the version of PowerShell your Function App uses. By the end, you’ll have practical options to choose from based on your scenario.

How to check if a module is available

To check if a specific module is available run the Get-Module command. For example for the Microsoft PowerApps Administration PowerShell module.

Get-Module -Name Microsoft.PowerApps.Administration.PowerShell -ListAvailable

How to check if CLI is available

You can verify PAC CLI availability by checking its path or running its version command:

& "c:/home/site/wwwroot/Modules/paccli/tools/pac.exe" --version

$pacPath = "c:/home/site/wwwroot/Modules/paccli/tools/pac.exe"
if (Test-Path $pacPath) {
    Write-Host "PAC CLI is installed at $pacPath"
} else {
    Write-Host "PAC CLI is NOT installed"
}
Get-Command pac.exe -ErrorAction SilentlyContinue

How to install CLI

You can install the CLI by running the script below directly in your Function App, or run it locally and then manually upload the extracted CLI folder to the Function App’s file system. For better organization, I recommend placing the CLI inside the Modules folder.

# Download PAC CLI NuGet package only needed once. You can also do this locally and manual place the PAC CLI files on the function apps file drive
Invoke-WebRequest -Uri "https://www.nuget.org/api/v2/package/Microsoft.PowerApps.CLI/1.50.1" -OutFile "paccli.nupkg"

# Extract NuGet package. You can also do this locally and manual place the PAC CLI files on the function apps file drive
Expand-Archive -Path "paccli.nupkg" -DestinationPath "c:/home/site/wwwroot/Modules/paccli"

How to install the Microsoft crmsdk coretools

How to install a module

Before installing any modules, make sure they aren’t already available in your Function App. You can either install the modules locally and upload the module folder to the Function App’s file system, or configure the Function App to install them automatically by updating the requirements.psd1 and host.json files.

  • Make sure that in the host.json file (c:\home\site\wwwroot\host.json) managedDependency is set to Enable true.
  • I included my whole host.json file to demonstrate where to place the code.
{
  "version": "2.0",
  "isDefaultHostConfig": true,
  "managedDependency": {
    "Enabled": true
  },
  "extensionBundle": {
    "id": "Microsoft.Azure.Functions.ExtensionBundle",
    "version": "[4.*, 5.0.0)"
  }
}
  • Open the requirements.psd1 file, or create a new one if it doesn’t exist.
  • Add the modules that need to be installed inside the @{ }.
  • In my example below, the modules are commented out, so they won’t be installed.
  • Restart your Function App to begin the installation process. This step can take several minutes to complete.
# This file enables modules to be automatically managed by the Functions service.
# See https://aka.ms/functionsmanageddependency for additional information.
#
@{
    # For latest supported version, go to 'https://www.powershellgallery.com/packages/Az'. 
    # To use the Az module in your function app, please uncomment the line below.
    #'Az.Accounts' = '2.*'
    #'Microsoft.PowerApps.Administration.PowerShell' = '1.*'
    #'Microsoft.PowerApps.PowerShell' = '1.*'
}
  • After the installation is done, make sure to import the installed modules.
Import-Module "c:/home/site/wwwroot/Modules/Microsoft.PowerApps.Administration.PowerShell/2.0.216/Microsoft.PowerApps.Administration.PowerShell.psd1" -Verbose
Import-Module "c:/home/site/wwwroot/Modules/Microsoft.PowerApps.PowerShell/1.0.45/Microsoft.PowerApps.PowerShell.psd1" -Verbose

How to upload file to the Function Apps drive

Each Windows-based Function App includes a file system where you can store files. You can access this file system through your browser using Kudu, available under the Advanced Tools settings.

  • Open your Function App and look for Advanced Tools or Kudu in the menu.
  • Click on Advanced Tools, then click on Go.
  • A new tab will open with the advanced Kudu tools.
  • Click on Debug console, then choose either CMD or PowerShell.
  • Navigate to the folder where you want to upload files. I most cases, this will be the C:\home\sites\wwwroot folder.
  • Drag and drop the files you want to upload into the selected folder

Power Platform: Monitoring a power app

When building apps in Power Apps, understanding what happens behind the scenes is essential for smooth performance and reliable functionality. The Monitor tool provides a powerful way to observe your app in action, offering real-time insights into its behavior and interactions.

Monitor acts as a live event viewer, capturing everything from data operations to user-triggered actions. It helps makers identify issues quickly, optimize performance, and validate logic without guesswork. Whether you’re troubleshooting a connector, analyzing load times, or verifying formula execution, Monitor gives you the visibility you need.

With Monitor, you can capture:

  • Performance metrics (load times, data refresh times)
  • Function calls (e.g., ClearCollect, Patch, Navigate)
  • Network requests (to SharePoint, Dataverse, APIs)
  • Errors and warnings
  • Trace logs (from Trace() statements)

How to use the monitor tool

  • In Power Apps Studio, from the app list, select Details → Live monitor under the app’s menu (3 dots).
  • The Monitor window will open for your app.
  • Click Play published app to run the app. It will open in a new browser tab.
  • Use the app as you normally would, focusing on the parts you want to monitor.
  • Events will appear live in the Monitor window as you interact with the app.
  • Use filters to narrow down event types such as Errors, Warnings, or Trace messages.
  • Click any event to view detailed information, including formula execution, data payload, and timing.

How to use Trace()

The Trace function allows you to send custom messages to the Monitor log while your app runs. This is useful for debugging and understanding the flow of your app. You can log simple text messages, variable values, or even complex objects and collections. You can also specify the severity of the message, such as Information, Warning, or Error. Trace is only available in canvas apps and does not work in model-driven apps.

To send a message only when a specific condition is met, wrap the Trace function inside an If statement. This helps you log errors or warnings only when they occur, instead of flooding the log with unnecessary messages.

Trace("Start of OnScreen"); // Manual text message

Trace("Value of varCompHeigh" & varCompHeight); // A variable

Trace("Value of gblAppColors" & JSON(gblAppColors)); // An object as JSON

Trace("Trace Warning", TraceSeverity.Warning); // Trace of type warning

Trace("Trace Critical", TraceSeverity.Critical); // Trace of type Critical

Trace("Trace Error", TraceSeverity.Error); // Trace of type Error

Trace("Trace Information", TraceSeverity.Information); // Trace of type Information

If(IsEmpty(colDesks), Trace("Collection is empty: " & JSON(colDesks), TraceSeverity.Error)) // Trace within If condition

Trace("End of OnStart"); // Manual text message

Logic App: Tips and tricks

Whether you’re just getting started with Logic Apps or looking to refine your workflows, this post shares practical tips that can save you time and headaches—especially when working with SharePoint integrations. From handling approval status correctly to formatting JSON for field updates and managing choice fields in conditions, these insights will help you build smarter, more reliable automations. Let’s dive into the details.

Approve or reject an SharePoint item

To approve or reject a SharePoint item, use the Set content approval status action. This cannot be done using Create item or Update item actions.

Using JSON to Update SharePoint Fields

When creating or updating SharePoint items in Logic Apps, you’ll need to use JSON formatting to set field values correctly.

{
  "Current Status": {
    "Value": "Closed"
  }
}

For a text or date fields:

{
  "Date": "YourDateValue",
  "Text": "Example"
}

For a number field:

{
  "Number": 1
}

Using the Approval Status Field in SharePoint

To check the approval status of a SharePoint item, refer to the Approval Status field (Dutch: Goedkeuringstatus). This field reflects whether an item is PendingApproved, or Rejected.

When using this field in Power Automate or other logic-based tools, keep in mind:

  • Always use {ModerationStatus} when referencing this field in condition actions.
  • The display name of the field is Approval Status.
  • The internal name used in conditions or expressions is {ModerationStatus}.
  • Although you might see _ModerationStatus in the URL when filtering or viewing list settings, that version cannot be used directly in expressions or dynamic content.

Condition check for SharePoint choice field

When working with choice fields in SharePoint (e.g. Status), you can’t directly compare with the field name in a condition. The actual value is nested deeper in the JSON structure. Instead of checking just Status, you need to check Status.Value. This ensures you’re comparing the actual selected value of the choice field, not the object that contains it.

@items('For_each')?['Status']?['Value']

Adding a Line Break (enter) in an Append to String action

When working with a For Each loop in Logic Apps, it is often useful to collect output from each iteration. One effective approach is to use the Append to string variable action. In my solution, I needed to build a list where each item appears on a new line. To achieve this, simply add the <br> HTML tag at the end of each appended string to insert a line break.

Power App: Tips & Tricks

Today, we will delve into some practical tips and tricks that can enhance your experience while working with Power Apps. Whether you’re a seasoned developer or just starting out, these tips will help you streamline your workflow and make the most out of the Power Platform.

In this post, we’ll cover various aspects of working with Dataverse forms in canvas apps, including how to handle different form modes, retrieve the last submitted data, and reset variables in SharePoint-integrated Power Apps. Additionally, we’ll explore how to use the concurrent function to load multiple data sources quickly, get current user details, and cache data for better performance.

Form modes

When working with a Dataverse form in a canvas app, you sometimes need different behavior for the edit, new, or view mode of the form. Each mode is represented by a number, and you can use the following code to check the current FormMode. Form2 is the name of the form.

If(Form2.Mode = 0, "Edit", Form2.Mode = 2, "View", "New")
Enum NameNumeric Value
FormMode.Edit0
FormMode.New1
FormMode.View2

It can also be done by comparing the Mode of the form SharePointForm1.LastSubmit.ID with the FormMode.Edit / View or New code.

If(Form2.Mode = FormMode.Edit, "Edit", Form2.Mode = FormMode.View, "View", "New")

Last submitted data

When working with a form to submit data to Dataverse you can get the last submitted data. You can get the ID of the created record by calling the LastSubmit followed by the name of the ID column.

Form1.LastSubmit.Contact

This can also be done with a SharePoint integration power app by calling the LastSubmit code from the SharePoint form.

SharePointForm1.LastSubmit.ID

Reset variables in SharePoint integrated Power App

When you set variables in a SharePoint integrated Power App don’t forget to reset them when the user closes the app either resetting the variables in the OnCancel or OnSave or resetting them when the form gets opened.

Set(varStatus, Blank());
Set(varFlag, false);

Use concurrent to load multiple sources quicker

When you want to store multiple sources locally, you can load them in a collect one after the other.

ClearCollect(Account, Accounts);
ClearCollect(Contact, Contacts);

But you can also load them in parallel by using the concurrent function. This will load them faster by loading them at the same time.

Concurrent(
    ClearCollect(colAccount, Accounts),
    ClearCollect(colContact, Contacts)
);

Get current users details

You can get the current user’s details by using the User() function.

User().EntraObjectId;
User().Email;
User().FullName;
User().Image;

Cache data that does not change but is used in multiple locations

When you are calling the same function again to access a resource to get the same data it is better (faster) to retrieve it once and store it in a variable.

Set(varCurrentUserName

Set(varUsername, User().FullName);
Set(varMyAccountName, LookUp(Accounts, 'Account Name' = "Contoso, Ltd."));

Drop-down not showing the correct values

Sometimes when you add a drop-down to a canvas app the displayed values are item 1, item 2 etc. Instead of the actual values. This happens when the drop-down list options are not loaded correctly.

Go to the DisplayFields property of the drop-down and set the it to [“Value2”] instead of [“Value”]. The canvas app will see that this is incorrect and change it back to [“Value”] and refresh the drop-down values. Now all the correct values will be visible.

Power App: How to export and import a SharePoint Power App Form

At this moment there is no out-of-the-box way to export/import a SharePoint Power App form between SharePoint list. Even when you duplicate the SharePoint List the custom SharePoint Power App form will not be duplicated. But fear not, there is a way to transfer the form. However its not for the faint of heart you will need to manual edit the forms code.

Exporting the form

  • Open the settings of the SharePoint list with the SharePoint Power App form.
  • Click on Form settings.
  • Click on See versions and usage; this will open the app in the Power App Studio.
  • Click on Export package.
  • Give the package a name and set the import setup to Create as new.
  • Click on Export.

Duplicate the SharePoint list

We will need a exact copy of the original SharePoint list, otherwise the names (references) will not be the same.

  • Click in SharePoint on the menu on the left on the +
  • Click on Existing list
  • Select the SharePoint site and the select your list, my list is called My Demo List.
  • Leave the name the same and click on Create.
  • A duplicated list is now created, but without the SharePoint Power App form.
  • For the manual changes we will need to get the list id
  • Open de list settings and copy the list ID from the URL.

Manually changing the references

  • Navigate to the exported SharePoint Power App form create a copy of it and unzip it.
  • Open the unzipped folder.
  • Navigate to Microsoft.PowerApps – Apps – [numeric value].
  • Open the JSON file with only numbers in its name in your favorite code editor (I am using Visual Studio Code).
  • Find the old list id and replace it with the new ID. Depended on you app, the ID might need to be replaces multiple times.
  • Now find the site URLs that reference the old site and change them to the new site. There might be multiple URLs that need to be updated, my app had 5.
  • Save the changes to the file.
  • Now we need to unzip the MSAPP File.
  • Change the type from msapp to zip and unzip the folder.
  • Open the unzipped folder.
  • Open the Properties.json and change the old URL to the new URL.
  • Open the DataSources file.
  • Change al the old URLs to the new URL, be aware there are some partial URLs that need to be changed.
  • Save all the changes and remake the zip file.
  • Remove the old MSAPP file.
  • Rezip the folder and set the name to be exactly the same as the old msapp file.
  • Make sure you did not add an extra folder layer to the new zip file.
  • Change the file type of the zip file to msapp.
  • Remove the unzipped folder.
  • Go to the top level of the folder and rezip the whole app.
  • Make sure you did not add an extra folder layer to the new zip file.

Importing the form

  • Upload the updated exported package (zip).
  • Change the name of the app, the names of app need to be unique.
  • If required setup the connections.
  • If required select the flows.
  • Click on import.
  • Wait for the import to finish.
  • Open the new (duplicated) SharePoint list.
  • Click on Integrate – Power Apps – Customize forms.
  • This will open the imported app.
  • Publish the app.
  • Go back to the list and create an item, the SharePoint Power App form will now be opened.
    • You might need to refresh the page for the app to appear.

Power Platform: Enhancing SharePoint Integrated Power Apps with Post-Submit Actions

Creating a seamless user experience in a SharePoint integrated Power App (Canvas App) can be challenging, especially when performing actions after form submission. Once a form is submitted, it closes, but the OnSuccess property allows you to run code post-submission.

In this blog, I’ll show you how to use the OnSuccess property to make changes to the newly created SharePoint item. Although you can’t use ThisItem or link directly to data cards, I’ll guide you through the process to ensure your app functions smoothly.

By the end, you’ll know how to enhance your Power App’s functionality and improve user experience. Let’s dive in!

Create a SharePoint list

  • Create a SharePoint list on any SharePoint site.
  • Add 1 text column named OnSuccesData.

Create the SharePoint integrated power app.

  • Open the created SharePoint list.
  • Click on Integrate, Power Apps, Customize Forms app.
  • This will create a basic SharePoint integrated power.
  • Remove the Attachments DataCard.
  • Click on the SharePointForm1 and add a custom datacard.
  • Add a label and a Text Input objects on the datacard.
  • Rename the label to lbl_OnSuccesData.
  • Rename the Text Input to txt_OnSuccesData.
  • Set the OnChange to the following code.
    • We need to store the Text value in a variable, because when you call directly for txt_OnSuccesData.Text it will work for editing items but not for creating items.
Set(varOnSuccesData, txt_OnSuccesData.Text);
  • Set the 2 objects below each other.
  • Set the text of the label to On Succes Data.
  • Set the Default of the text input to “”.
  • Create a new blank Power Automate flow from the power app.
  • Name the flow to Actions after submission.
  • Set the following text inputs.
    • ItemID
    • OnSuccesData
  • Add the SharePoint action Update item and set it for the earlier created SharePoint list.
  • Set the Id to ItemID from the power app.
  • Set On Succes Data to OnSuccesData from the power app.
  • Save the Power Automate flow.
  • Open the Power App again.
  • Select the OnSuccess property of the SharePointForm1 object.
  • Add before the ResetForm(Self); code the following code to start the Power Automate flow.
Actionsaftersubmission.Run(SharePointForm1.LastSubmit.ID, varOnSuccesData);
  • Test your app by putting a text in the title and a text in the second On Succes Data text input object.
  • After you save the form, the flow will start and store the On Succes Data in the SharePoint on success data column.

Power Platform: QR Codes in a Canvas App

Creating QR codes in a canvas app can significantly enhance user experience by providing quick access to links and information. QR Codes are the way to go if you want to share a link from a canvas app. In this blog, I will explore two efficient methods to generate QR codes: using the QR Code connector and an open source API, both options use the goqr.me API endpoint. These approaches will help streamline the process and offer flexibility in implementation, catering to various business needs. 

Methode 1: Using the QR Code connector

This method utilizes the GoQR (Independent Publisher) connector available in Power Apps to generate QR codes effortlessly.

  • Create a new blank canvas app.
  • Click on the Data tab and search for QR Code.
  • Click on the GoQR (Independent Publisher).
  • Then click on GoQR (Independent Publisher) to add the connection.
  • Add a Text input.
  • Add a button, name the button Create QR Code.
  • Set the OnSelect of the Create QR Code button to the following code.
Set(QRCode, 'GoQR(IndependentPublisher)'.Create(TextInput1.Text))
  • Add another button, name the button Reset QR Code.
  • Set the OnSelect of the Reset QR Code button to the following code.
Set(QRCode, Blank())
  • Add an image object.
  • Set the image property to the following code.
QRCode
  • Type an URL in the text input and click on Create QR Code to generate the QR Code.
  • Click on the Reset QR Code button to reset the QR Code.

Methode 2: Generating QR Code via a direct API call

For users who prefer a more direct approach, it is possible to call the goqr.me API directly from Power Apps. This method is flexible and does not require adding a connector.

  • Create a new blank canvas app.
  • Add a Text input.
  • Add a button, name the button Create QR Code.
  • Set the OnSelect of the Create QR Code button to the following code.
    Make sure the name of the text input is correct.
Set(QRCode, "https://api.qrserver.com/v1/create-qr-code/?size=150x150&data=" & TextInput2.Text)
  • Add another button, name the button Reset QR Code.
  • Set the OnSelect of the Reset QR Code button to the following code.
Set(QRCode, Blank())
  • Add an image object.
  • Set the image property to the following code.
QRCode
  • Type an URL in the text input and click on Create QR Code to generate the QR Code.
  • Click on the Reset QR Code button to reset the QR Code.

Power Platform: Analyse email attachments with AI

In today’s fast-paced business environment, leveraging automation and artificial intelligence (AI) is crucial for maintaining efficiency and gaining insights. This blog post explores how to create a Power Automate flow that reads emails with attachments, extracts content from images or PDF documents using AI, and can perform various analyses on the extracted text. For instance, you can determine the sentiment, generate summaries, or classify emails as purchase requests or complaints and routing then accordingly. By integrating these advanced technologies, businesses can streamline their processes, enhance decision-making, and stay ahead in the competitive landscape.

AI Generated image

Create an AI model

First, we need to create a custom AI document model or AI Prompt that receives the PDF content and analyses it. But off course we can also use a default model. In this example we will be using the default AI Sentiment.

Create a Power Automate Flow

In this flow we will get all the attachments from the email and get the content ready to be sent for a sentiment analysis.

  • Create a Power Automate flow with the trigger, When a new email arrives in a shared mailbox (V2).
  • Connect this with the required email box and select the option Include Attachments to Yes.
  • Add the action Initialize variable and call it Initialize variable – Attachment Content.
  • Add a Scope action called Scope – Get PDF Content.
  • We are going to combine all the content of all the found PDF attachments into one variable. You could also send each attachment file separately.
  • First, we need to filter the attachment files to only get the PDF file.
  • Add a Filter Array action and call it Filter Array – Attachment for PDF.
  • Set the from to Attachments.
  • Set the first value to Attachment Content type.
  • Set the filter to is equal to.
  • Set the second value to application/pdf.
  • Add an Append to string variable action and name it Append to string variable – Attachment Content.
  • Set the Name to Attachment Content.
  • Set the Value to Content (from the filter array) – .
  • An apply to each will be automaticallycreated, name it Apply to each – Found PDF.
  • Add a Recognize text in an image or a PDF document below the apply to each.
  • Set the image to Attachment Content.
  • Add a Scope and name it Scope – AI Sentiment.
  • Add a Create Text with GPT using a prompt action and name it Create Text with GPT using a prompt – Get sentiment.
  • Set AI Sentiment as the Prompt.
  • Set Input Text to Attachment Content variable.
  • Your flow now looks like this.

Power Platform: Use AI to evaluate every incoming email

Leveraging AI for email management not only saves time but also reduces the risk of human error. By automating the evaluation process, businesses can ensure that important emails, such as orders, are promptly and accurately identified, allowing for quicker response times and improved customer satisfaction. Embracing AI in email workflows is a smart move towards greater productivity and operational excellence.

In this article, I explain how to create an AI prompt model using Microsoft GPT to streamline email processing. By integrating Power Automate, the flow sends the content of each new email to the AI model, which then determines if the email is an order. If identified as an order, the AI responds with a JSON output indicating a positive result. This approach enhances the efficiency and accuracy of order processing through intelligent automation.

Create an AI model

For this blog I create a simple AI prompt to evaluate if a incoming email is a request for an order. The actual prompt is more complicated but confidential.

  • Open the AI hub aka AI Builder and select the Create text with GPT using a prompt.
  • Give the prompt a name.
  • Create three input parameters.
    • Email
    • EmailSubject
    • Attachments
  • Select by Output JSON (preview) and click on Edit.
  • Add the following JSON code.
{
      "Order": "true"
}
  • Set the Model to either GPT 3.5 (cheaper but less accurate) or GPT 4 (more expensive and more accurate).
  • Set the Temperature to 0.
  • Set the Prompt as follows or make your own prompt.
  • Save the prompt.

Create a Power Automate Flow

The Power Automate flow will start for every incoming email and will send to the AI model, the email body, subject and names of the attachments. The model will return its determination in JSON form.

  • Create a new Power Automate flow with an outlook/email trigger, When a new email arrives in a shared mailbox.
  • Add an Initialize variable action to create a variable called All attachment names.
  • Add an Append to string variable and select by the name the All attachment names variable.
  • Set for the value the attachments of the email, with the following code. This will automatically add a Apply to each action.
items('Apply_to_each_-_Attachment')?['name'] - 
  • Add the Create text with GPT using a prompt action.
  • Select your created AI Prompt.
  • Set by attachments the variable All attachment names.
  • Set by Email the Body of the email.
  • Set by EmailSubject the Subject of the email.
  • This will start the AI model and it will return its results to the flow.
  • Form here on you can add in the requered steps for your specific process and test the process.

Power Automate: Set email category

In a recent AI project, I developed a solution to evaluate every incoming email in a shared mailbox using an AI model (GPT with prompt). To inform users of the shared mailbox that an email has been processed, the email is flagged with a custom Outlook category. This process leverages a special HTTP action for Outlook, simplifying the implementation. Notably, there is no need to set up any special permissions if the flow owner already has access to the shared mailbox. This example does not cover the specifics of communicating with the AI through Power Automate.

Creating custom category in Outlook

  • Open Microsoft Outlook.
  • Click on Category in the Home Ribbon.
  • Click on All Categories.
  • Click on New.
  • Set a name and select a color.
  • Click on OK followed by Clicking on OK.
  • You have now created the custom Outlook category.

Setting the category with Power Automate

  • Create a new Power Automate flow with an outlook/email trigger. For example: When a new email arrives in a shared mailbox.
  • Add the Send an HTTP request action.
  • Set the URI to be following code.
https://graph.microsoft.com/v1.0/me/mailFolders/Inbox/messages/triggerOutputs()?['body/id']
  • Set the method to PATCH
  • Use the following JSON code for the body
{
"categories": ["AI Finished"]
}
  • Set the Content-Type to application/json.
  • Save the flow.