Skip to main content

Azure Automation is a powerful cloud-based service designed to automate repetitive tasks. Within the context of the Power Platform, Azure Automation serves as a complementary tool to extend automation capabilities beyond the low-code/no-code paradigm of Power Automate.

Power Platform CLI is not out of the box available in Azure Automation. Thanks to the community, I found out how to use it.

Azure Automation connector in Power Automate

Azure Automation has its own connector in Power Platform. In a runbook, you can easily define parameters. These parameters show up in the Power Platform connector and are passed to the runbook.

Power Platform CLI installation

As the module is not out of the box available in Azure Automation, it must be installed for every run.

Thanks to Henry who suggested this on GitHub.

Add following function to your runbook:

Function InstallPac{
    # dotnet tool install --global Microsoft.PowerApps.CLI.Tool
    # dotnet tool install --global Microsoft.PowerApps.CLI
    
    Write-Output "Installing Microsoft Power Platform CLI..."
    $pacDownloadUrl = "https://www.nuget.org/api/v2/package/Microsoft.PowerApps.CLI"
    # Expand-Archive need .zip extension https://github.com/actions/runner/issues/1883
    $pacInstallFile = "$($env:TEMP)\$($pacDownloadUrl.Split("/")[-1])" + $(If(("$($env:TEMP)\$($pacDownloadUrl.Split("/")[-1])" -replace '^.*(?=.{4}$)') -ne ".zip"){".zip"})
    $pacInstallFolder = $env:LOCALAPPDATA + "\Microsoft\PowerAppsCLI\"
    $pacToolsFolder = $pacInstallFolder + "tools\"

    Write-Output "Downloading pac Nuget package as zip file..."
    Invoke-WebRequest $pacDownloadUrl -OutFile $pacInstallFile

    Write-Output "Expand pac zip file to $pacInstallFolder"
    Expand-Archive -Path $pacInstallFile -DestinationPath $pacInstallFolder

    Write-Output "Set Enviroment variable PATH"
    # https://community.dynamics.com/blogs/post/?postid=1ccd34d1-70fb-4c16-8c04-8a9aa23a842c
    $env:PATH = $env:PATH + $(If($env:PATH[-1] -ne ";"){";"}) + $pacToolsFolder + ";"
}

Don’t forget to call the function in your runbook before executing Power Platform CLI commands.

Wouter

Leave a Reply