Skip to content

Instantly share code, notes, and snippets.

@jackawatts
Created August 29, 2024 00:19
Show Gist options
  • Save jackawatts/79ce64926a22b0439e4364d5d014c8a3 to your computer and use it in GitHub Desktop.
Save jackawatts/79ce64926a22b0439e4364d5d014c8a3 to your computer and use it in GitHub Desktop.

Check if exists before deletion without using exists

Write-Host "Checking if '$(legacy_functionapp_name) exists"
$functionAppCheck = az functionapp list --query "[?name=='$(legacy_functionapp_name)']" | ConvertFrom-Json
$functionAppExists = $functionAppCheck.Length -gt 0

Write-Host "Exists: $functionAppExists"
if ($functionAppExists) {
    Write-Host "Deleting legacy function app"
    az functionapp delete -n $(legacy_functionapp_name) -g $(resourcegroup_name)
}
else {
    Write-Host "Doing nothing"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment