Home NewsX Run PowerShell Scripts directly in Logic Apps with inline action

Run PowerShell Scripts directly in Logic Apps with inline action

by info.odysseyx@gmail.com
0 comment 7 views


The new inline PowerShell action, now available in preview, adds flexibility to Logic Apps by allowing users to embed PowerShell scripts directly into their workflows. This opens up new possibilities for complex integrations, and we’re excited to demonstrate its potential with the bank reconciliation workflow demo.

What are inline PowerShell actions?

Similar to the recently released inline C# actions, inline PowerShell actions allow you to include custom PowerShell scripts directly in your Logic Apps. standard Workflows allow you to write and execute scripts within the workflow designer, without requiring any additional services. The action supports dynamic content from previous steps and returns the results of PowerShell code for use in subsequent actions.

Key Benefits:

  • Management and Costs: Embedding PowerShell scripts directly into your workflows reduces the complexity and cost of managing separate services.
  • Dedicated scripting space: This task generates a dedicated .ps1 file to provide a personalized scripting environment.
  • Seamless deployment: Scripts are distributed along with the workflow to ensure smooth and efficient execution.
  • Support for public and private modules: Inline PowerShell actions support up to 10 public modules from the PowerShell Gallery, such as Az or SqlServer, by enabling managed dependencies. You can also create and use private modules for custom functionality within Logic Apps, improving code reuse and workflow maintainability.

Demonstrating the Power of Inline PowerShell: Bank Statement Workflow

To demonstrate the capabilities of this new feature, we have developed a bank reconciliation workflow. This demo shows how to automate the bank reconciliation process by starting and de-allocating virtual machines (VMs) using an inline PowerShell script. The workflow is triggered on a recurring schedule to start the VM, check for required files, and upload them to storage. If the files are not found, the workflow automatically notifies the relevant teams to resolve the issue. Next is Sample demo on GitHub Give it a try.

Prerequisites:

  1. Azure VM with RDP enabled. Read more about the setup. here
  2. Azure Storage account with configured blobs

Workflow Analysis:

The workflow is as follows:

Shapart_0-1723749745090.png

  1. Workflow Trigger (Recurring): The process starts with a scheduled trigger that starts the bank reconciliation workflow on a regular basis. In our case, it is set to Daily since new bank statements from our partner bank are uploaded to the server for processing every day.
  2. Start a VM with PowerShell: Inline PowerShell tasks are used to start a virtual machine and set up the environment required for orchestration tasks. Here is my script:
    Shaphat_3-1723749901551.png

    memo: Don’t forget to add “Connect-AzAccount -Identity” so that the managed identity is configured and the Logic App can access the VM.

  3. List files in a folder: When the VM is running, the workflow lists all files and subfolders in the specified directory and checks if the required reconciliation files exist in the defined folder path on the server.
  4. Iterate through files (for each loop): The workflow loops through each file found in the folder and processes it individually. Use the token selector to select the “Folder Item” parameter.
  5. Condition check: The condition is evaluated to determine if the required file exists.
    1. Physical Path: When a file is found, the workflow retrieves the file contents and uploads them to a storage container for further processing or archiving.
      1. Use the Get File Content action of the File System Connector to retrieve each file and its contents.
      2. Upload the file to your storage account so that your parent bank can process it.
    2. Invalid Path: If the file cannot be found, the workflow sends an email notification to the appropriate team member informing them that the partner bank has not uploaded the file to their server.
  6. Deallocate VMs using PowerShell: After file processing is complete, another inline PowerShell task deallocates the VMs to optimize resource usage and reduce costs.

    Shapart_2-1723749878647.png

Running a workflow

The workflow is triggered automatically every day. Keep the following in mind:

  1. Upload bank transaction details to a file share folder on the VM so that the workflow can collect the bank transaction details on a daily basis.
  2. Comment out the ‘Az’ versioning line in your requirements.psd1 file so that the script uses the appropriate version of the Az module. You can find this file using Advanced Tools in Kudu’s Poral. For detailed instructions, see: here.
    Shapart_4-1723749949870.png

Considerations and Limitations

Inline PowerShell actions are powerful, but there are some considerations and limitations to keep in mind.

  • Script execution period: The maximum duration is 10 minutes. For longer scenarios, consider providing feedback to Microsoft for extended support.
  • Output size: Output size is limited to 100MB.
  • Script Management: Scripts are saved as .ps1 files inside the workflow folder and can be copied from the KuduPlus console to be reused in other workflows.

conclusion

The introduction of inline PowerShell actions in Azure Logic Apps is a significant advancement, enabling more advanced and integrated workflows. Whether you need to manage Azure resources, perform administrative tasks, or automate complex processes, this new capability provides the tools you need.

For more detailed instructions, please refer to the official documentation. Add and run PowerShell scripts in Azure Logic Apps.





Source link

You may also like

Leave a Comment

Our Company

Welcome to OdysseyX, your one-stop destination for the latest news and opportunities across various domains.

Newsletter

Subscribe my Newsletter for new blog posts, tips & new photos. Let's stay updated!

Laest News

@2024 – All Right Reserved. Designed and Developed by OdysseyX