#ODataQuery
Explore tagged Tumblr posts
Text
Finding orphaned API Connections in Logic Apps
So, Logic Apps has a concept of API Connections, where the information to connect to things like Azure Storage, Azure Service Bus etc. is stored. These connections can be used by one Logic App, or they can be used by several within the Resource Group.
So far it is brilliant.
The issue comes when the team has created lots of Logic Apps and connections for development and testing purposes. Because when you delete the Logic Apps, the API Connections stay.
Within each Logic App, you can check which API COnncetions are used, nice. But for an API Connection, you can’t check which Logic Apps is using it, or if it is even used, crap!
Since the Logic Apps have connections to the API Connections, this should be easily done with Powershell, right? Wrong! It turns out that the information about the API Connections is located in some custom named collection objects. Not being in an array, they don’t have an enumerator, and are not possible to iterate.
Well, with some string work I finally got a script that lists the unused API Connection in a subscription. (And the used ones in Green if you include what is commented)
The script doesn’t delete anything, so it is safe to run, but I don’t take any responsibility for wrongly deletes objects. So be careful and verify the results.
$Tab = [char]9 $logigAppStringCollection = New-Object System.Collections.ArrayList foreach($res in Get-AzureRmResource -ODataQuery "`$filter=resourcetype eq 'microsoft.logic/workflows'" | Sort-Object $_.ResourceGroupName) { $logicApp = Get-AzureRmLogicApp -ResourceGroupName $res.ResourceGroupName -Name $res.Name $logigAppStringCollection.Add($logicApp.Parameters.'$connections'.Value) | Out-Null } foreach ($i in Get-AzureRmResource -ODataQuery "`$filter=resourcetype eq 'microsoft.web/connections'" | Sort-Object $_.ResourceGroupName) { $used = 'Unused' foreach($logicAppString in $logigAppStringCollection) { try { if ($logicAppString.ToString().Contains($i.ResourceId.ToString())) { $used = 'Used' } } catch{ } } if ($used -eq 'Unused') { Write-Host $used $Tab $i.ResourceId -ForegroundColor Red } #else #{ #Write-Host $used $Tab $i.ResourceId -ForegroundColor Green #} }
0 notes