Skip to content

Instantly share code, notes, and snippets.

@oledid
Last active October 25, 2022 18:37
Show Gist options
  • 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
}
@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