Powershell | Create "Deploy to Azure" button

About every half year I need to create the famous “Deploy to Azure” button… so here is a quick’n’dirty Powershell script which creates the link and the proper markdown. There is also support to include the UI definition/wizard file.

If you don’t have/need a UI wizard file, just leave it empty (“”).

# edit here
$strTemplateUrl = "https://raw.githubusercontent.com/hoferandrea/Sentinel-Playground-Bicep-Edition/main/mainPlayground.json"
$strUiWizardUrl = ""

# do not edit
$strBaseUrl = "https://portal.azure.com/#create/Microsoft.Template/uri"
$strEncodedTemplateUrl = [uri]::EscapeDataString($strTemplateUrl)
$strEncodedUiWizardUrl = [uri]::EscapeDataString($strUiWizardUrl)

If($strUiWizardUrl -eq ""){
    "create deploy button without ui definition..."
    $strUrl = "$strBaseUrl/$strEncodedTemplateUrl"
} Else{
    "create deploy button with ui definition..."
    $strUrl = "$strBaseUrl/$strEncodedTemplateUrl/createUIDefinitionUri/$strEncodedUiWizardUrl" 
}
"direct link: $strUrl"
"markdown: [![Deploy to Azure](https://aka.ms/deploytoazurebutton)]($strUrl)"

example without UI wizard file:

# edit here
$strTemplateUrl = "https://raw.githubusercontent.com/hoferandrea/Sentinel-Playground-Bicep-Edition/main/mainPlayground.json"
$strUiWizardUrl = ""

Deploy to Azure

example with UI wizard file:

# edit here
$strTemplateUrl = "https://raw.githubusercontent.com/hoferandrea/Sentinel-Playground-Bicep-Edition/main/mainPlayground.json"
$strUiWizardUrl = "https://raw.githubusercontent.com/hoferandrea/Sentinel-Playground-Bicep-Edition/main/mainPlaygroundUi.json"

Deploy to Azure