Check the details of my Logic App SAP connectors
  • Updated on 04 Mar 2020
  • 2 minutes to read
  • Contributors
  • Print
  • Comments
  • Share
  • Dark
    Light

Check the details of my Logic App SAP connectors

  • Print
  • Comments
  • Share
  • Dark
    Light

We were using Logic Apps and the SAP connector for a number of integration scenarios. One of the challenges when you are developing a lot of Logic Apps is you can end up with quite a few API Connections which represent the connectors you use in Logic Apps. We had a number of different SAP environments and I wanted to be able to check which of our connectors were pointing to which SAP environment. This is pretty tricky to do because the connectors dont easily allow you to compare settings across multiple connectors.

I put together the below powershell script which will look through all of the API Connectors in your resource group. It will look for all connectors which match the expression '/managedApis/sap' which indicates they are a SAP connector. It will then iterate over the json for these connectors and it will look at the properties for the connector. It will then output a csv file at the end allowing you to easily look across all of the connectors and see how their different properties compare. Ideally they should all be pointing to the same SAP instance but in practice I found many of our connectors were pointing to the test environment not the dev environment so we were able to correct these and run the script again to see everything was ok.

If you are using other connectors it should be quite easy to modify this script to match your other connectors and to compare their properties.

Full Script

#This will check for SAP API Connections and look at where they are pointing to

$subscriptioName = 'My Subscription'
$resourceGroupName = 'My Resource Group'
$sapExpression = '/managedApis/sap'

#use the collection to build up objects for the table
$connectorList = [System.Collections.ArrayList]::new(); 

az login
az account set --subscription $subscriptioname

#Get Subscription Info
$subscription = Get-AzSubscription -SubscriptionName $subscriptioName
$subscriptionId = $subscription.Id
Write-Host 'Subscription Id: ' $subscriptionId

#Get Resource Group Info
$resourceGroup = Get-AzResourceGroup -Name $resourceGroupName
$resourceGroupPath = $resourceGroup.ResourceId
Write-Host 'Resource Group Path: '  $resourceGroupPath


$resourceName = ''
$resources = Get-AzResource -ResourceGroupName $resourcegroupName -ResourceType Microsoft.Web/connections
$resources | ForEach-Object { 
    
    $resourceName = $_.Name

    $connectorUrl = $resourceGroupPath + '/providers/Microsoft.Web/connections/' + $resourceName + '?api-version=2018-07-01-preview'
    #Write-Host 'Url: ' $connectorUrl

    $connectorJson = az rest --method get --uri $connectorUrl
    $connectorJsonText = $connectorJson | ConvertFrom-Json 

    if($connectorJson -match $sapExpression)
    {
        Write-Host 'Connector is a SAP connector'

        Write-Host 'Id: '$connectorJsonText.id
        Write-Host 'Name: '$connectorJsonText.name
        Write-Host 'Display Name: '$connectorJsonText.properties.displayName
        Write-Host 'appServerHost: '$connectorJsonText.properties.parameterValues.appServerHost
        Write-Host 'appServerService: '$connectorJsonText.properties.parameterValues.appServerService
        Write-Host 'client: '$connectorJsonText.properties.parameterValues.client
        Write-Host 'systemNumber: '$connectorJsonText.properties.parameterValues.systemNumber
        Write-Host 'changedTime: '$connectorJsonText.properties.parameterValues.changedTime
        Write-Host 'createdTime: '$connectorJsonText.properties.parameterValues.createdTime
        Write-Host ''
        Write-Host ''


        #Create simpler object so we can output to a table
        $azureConnector = New-Object -TypeName psobject
        $azureConnector | Add-Member -MemberType NoteProperty -Name 'Id' -Value $connectorJsonText.id
        $azureConnector | Add-Member -MemberType NoteProperty -Name 'name' -Value $connectorJsonText.name
        $azureConnector | Add-Member -MemberType NoteProperty -Name 'Display Name' -Value $connectorJsonText.properties.displayName
        $azureConnector | Add-Member -MemberType NoteProperty -Name 'appServerHost' -Value $connectorJsonText.properties.parameterValues.appServerHost
        $azureConnector | Add-Member -MemberType NoteProperty -Name 'appServerService' -Value $connectorJsonText.properties.parameterValues.appServerService
        $azureConnector | Add-Member -MemberType NoteProperty -Name 'client' -Value $connectorJsonText.properties.parameterValues.client
        $azureConnector | Add-Member -MemberType NoteProperty -Name 'systemNumber' -Value $connectorJsonText.properties.parameterValues.systemNumber

        $connectorList.Add($azureConnector)
    }    
}

$connectorList | Export-Csv -Path C:\Temp\LogicAppSAPConnectors.csv
Was this article helpful?