Quickstart: Create and manage workflows with Azure PowerShell in Azure Logic Apps

Applies to: Azure Logic Apps (Consumption)

This quickstart shows how to create and manage automated workflows that run in Azure Logic Apps by using Azure PowerShell. From PowerShell, you can create a Consumption logic app in multi-tenant Azure Logic Apps by using the JSON file for a logic app workflow definition. You can then manage your logic app by running the cmdlets in the Az.LogicApp PowerShell module.

Note

This quickstart currently applies only to Consumption logic app workflows that run in multi-tenant Azure Logic Apps. Azure PowerShell is currently unavailable for Standard logic app workflows that run in single-tenant Azure Logic Apps. For more information, review Resource type and host differences in Azure Logic Apps.

If you're new to Azure Logic Apps, learn how to create your first Consumption logic app workflow through the Azure portal, in Visual Studio, or in Visual Studio Code.

Prerequisites

Prerequisites check

Before you start, validate your environment:

  • Sign in to the Azure portal and check that your subscription is active by running Connect-AzAccount.

  • Check your version of Azure PowerShell by running Get-InstalledModule -Name Az. For the latest version, see the latest release notes.

    If you don't have the latest version, update your installation by following the steps for Update the Azure PowerShell module.

Example - Create resource group

If you don't already have a resource group for your logic app, create the group with the New-AzResourceGroup cmdlet. For example, the following command creates a resource group named testResourceGroup in the location westus.

New-AzResourceGroup -Name testResourceGroup -Location westus

The output shows the ProvisioningState as Succeeded when your resource group is successfully created:

ResourceGroupName : testResourceGroup
Location          : westus
ProvisioningState : Succeeded
Tags              :
ResourceId        : /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/testResourceGroup

Workflow definition

Before you create a new logic app or update an existing logic app by using Azure PowerShell, you need a workflow definition for your logic app. In the Azure portal, you can view your logic app's underlying workflow definition in JSON format by switching from Designer view to Code view.

When you run the commands to create or update your logic app, your workflow definition is uploaded as a required parameter (Definition) or (DefinitionFilePath) depending on the parameter set. You must create your workflow definition as a JSON file that follows the Workflow Definition Language schema.

Create logic apps from PowerShell

To create a logic app workflow from Azure PowerShell, use the cmdlet New-AzLogicApp with a JSON file for the definition.

Example - Create logic app

This example creates a workflow named testLogicApp in the resource group testResourceGroup with the location westus. The JSON file testDefinition.json contains the workflow definition.

New-AzLogicApp -ResourceGroupName testResourceGroup -Location westus -Name testLogicApp -DefinitionFilePath .\testDefinition.json

When your workflow is successfully created, PowerShell shows your new workflow definition.

Update logic apps from PowerShell

To update a logic app's workflow from Azure PowerShell, use the cmdlet Set-AzLogicApp.

Example - Update logic app

This example shows how to update the sample workflow created in the previous section using a different JSON definition file, newTestDefinition.json.

Set-AzLogicApp -ResourceGroupName testResourceGroup -Name testLogicApp -DefinitionFilePath .\newTestDefinition.json

When your workflow is successfully updated, PowerShell shows your logic app's updated workflow definition.

Delete logic apps from PowerShell

To delete a logic app's workflow from Azure PowerShell, use the cmdlet Remove-AzLogicApp.

Example - Delete logic app

This example deletes the sample workflow created in a previous section.

Remove-AzLogicApp -ResourceGroupName testResourceGroup -Name testLogicApp

After you respond to the confirmation prompt with y, the logic app is deleted.

Considerations - Delete logic app

Deleting a logic app affects workflow instances in the following ways:

  • Azure Logic Apps makes a best effort to cancel any in-progress and pending runs.

    Even with a large volume or backlog, most runs are canceled before they finish or start. However, the cancellation process might take time to complete. Meanwhile, some runs might get picked up for execution while the runtime works through the cancellation process.

  • Azure Logic Apps doesn't create or run new workflow instances.

  • If you delete a workflow and then recreate the same workflow, the recreated workflow won't have the same metadata as the deleted workflow. You have to resave any workflow that called the deleted workflow. That way, the caller gets the correct information for the recreated workflow. Otherwise, calls to the recreated workflow fail with an Unauthorized error. This behavior also applies to workflows that use artifacts in integration accounts and workflows that call Azure functions.

Show logic apps in PowerShell

To get a specific logic app workflow, use the command Get-AzLogicApp.

Example - Get logic app

This example returns the logic app testLogicApp in the resource group testResourceGroup.

Get-AzLogicApp -ResourceGroupName testResourceGroup -Name testLogicApp

Next steps

For more information on Azure PowerShell, see the Azure PowerShell documentation.

You can find additional Logic Apps script samples in Microsoft's code samples browser.