Skip to content

Instantly share code, notes, and snippets.

@oledid
Last active October 25, 2022 18:37
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save oledid/ab8571045f33a9bc419c0ee27a9e8253 to your computer and use it in GitHub Desktop.
Save oledid/ab8571045f33a9bc419c0ee27a9e8253 to your computer and use it in GitHub Desktop.
Resubmit failed logic app runs
############################################################
# Resubmit failed logic app runs
############################################################
# Sources:
# https://github.com/Azure/logicapps/tree/master/scripts/resubmit-all-failed-runs
# https://github.com/Azure/azure-powershell/issues/7752
import-module Az
$subscriptionId = "<id here>"
$resourceGroupName = "<name here>"
$logicAppName = "<name here>"
$startDateTime = "2021-01-01 00:00:00" # change these
$endDateTime = "2021-01-01 00:00:00" # change these
Connect-AzAccount # interactive
Set-AzContext -SubscriptionId $subscriptionId
write-host "Fetching runs..."
$runs = Get-AzLogicAppRunHistory -FollowNextPageLink -ResourceGroupName $resourceGroupName -Name $logicAppName | where { $_.Status -eq 'Failed' -and $_.StartTime -gt $startDateTime -and $_.StartTime -lt $endDateTime }
$runsCount = $runs.Count
write-host "Found $runsCount runs"
$context = [Microsoft.Azure.Commands.Common.Authentication.Abstractions.AzureRmProfileProvider]::Instance.Profile.DefaultContext
$token = [Microsoft.Azure.Commands.Common.Authentication.AzureSession]::Instance.AuthenticationFactory.Authenticate($context.Account, $context.Environment, $context.Tenant.Id.ToString(), $null, [Microsoft.Azure.Commands.Common.Authentication.ShowDialog]::Never, $null, $dexResourceUrl).AccessToken
$headers = @{
'Authorization' = 'Bearer ' + $token
}
Foreach($run in $runs) {
$uri = 'https://management.azure.com/subscriptions/{0}/resourceGroups/{1}/providers/Microsoft.Logic/workflows/{2}/triggers/{3}/histories/{4}/resubmit?api-version=2016-06-01' -f $subscriptionId, $resourceGroupName, $logicAppName, $run.Trigger.Name, $run.Name
Invoke-RestMethod -Method 'POST' -Uri $uri -Headers $headers
write-host "+1"
start-sleep -Milliseconds 100
}
@PowerRanger83
Copy link

The script works like a charm but has a minor Bug. The URI generated in Line 35 should look like this:

$uri = 'https://management.azure.com/subscriptions/{0}/resourceGroups/{1}/providers/Microsoft.Logic/workflows/{2}/triggers/{3}/histories/{4}/resubmit?api-version=2016-06-01' -f $subscriptionId, $resourceGroupName, $logicAppName, $run.Trigger.Name, $run.Name

so instead of "-f $subscription.Id" it should be "-f $subscriptionId"

Thanks a lot for this snippet

@oledid
Copy link
Author

oledid commented Oct 25, 2022

@PowerRanger83 thanks, fixed!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment