functions/Add-AppScanConnector.ps1

<#
.SYNOPSIS
  
Create a single AppScan Enterprise connector
  
.DESCRIPTION
Adds a single AppScan Enterprise connector using the tool connector config API endpoints
  
.EXAMPLE
Add-AppScanConnector "My Code Dx Project" "Amazing AppScan Connector 1" https://my.appscan.server.local MyAPIKey MySecretKey MyRepoID MyRepoName MyAppID
 
Output (entry ID)
 
  
#>


Function Add-AppScanConnector
{
    [cmdletbinding()]
    param(
        [Parameter(Mandatory=$true)]
            [string]$ProjectName,
        [Parameter(Mandatory=$true)]
            [string]$NewConnectorName,
        [Parameter(Mandatory=$true)]
            [string]$ServerURL,
        [Parameter(Mandatory=$true)]
            [string]$APIKey,
        [Parameter(Mandatory=$true)]
            [string]$SecretKey,
        [Parameter(Mandatory=$true)]
            [string]$AppID
    )
    
    # Get the Code Dx project ID from the name
    $projects = Get-Projects
    $ProjectHash = @{}
    $projects.projects | ForEach-Object {
        $ProjectHash[$_.name] = $_.id
    }
    $ProjectID = $ProjectHash.$ProjectName
    
    # Create a blank tool connector
    $ConnectorInfo = Add-BlankConnector $ProjectID "AppScan Enterprise" $NewConnectorName
    $ConnectorID = $ConnectorInfo.id
    
    # Update the blank tool connector with the proper configuration info
    $uri = $CDXSERVER + "/x/tool-connector-config/values/" + $ConnectorID

    $IntervalInfo = [pscustomobject]@{
        'daily' = '03:00'
    }
    
    $body = ConvertTo-Json @{
        'url' = $ServerURL
        'api_key' = $APIKey
        'info_severity' = $true
        'low_severity' = $true
        'medium_severity' = $true
        'high_severity' = $true
        'critical_severity' = $true
        'auto-refresh-interval' = $IntervalInfo
        'secret_key' = $SecretKey
        'selected_application' = $AppID
        'available-during-analysis' = $true
    }

    Write-Verbose ( $body | Format-Table | Out-String )

    $CreateASE = Invoke-RestMethod -Uri $uri -Method Put -Body $body -Headers $headers -ContentType "application/json" 
    Write-Verbose ( $CreateASE | Format-Table | Out-String )

    Return $ConnectorID

}