functions/Add-TenableSCConnector.ps1

<#
.SYNOPSIS
  
Create a single tenable SC connector
  
.DESCRIPTION
Adds a single tenable SC connector using the tool connector config API endpoints
  
.EXAMPLE
Add-TenableSCConnector "My Code Dx Project" "Amazing tenable SC Connector 1" https://my.tenablesc.server.local MyAccessKey MySecretKey MyRepoID MyRepoName MyAssetID
 
Output (entry ID)
 
  
#>


Function Add-TenableSCConnector
{
    [cmdletbinding()]
    param(
        [Parameter(Mandatory=$true)]
            [string]$ProjectName,
        [Parameter(Mandatory=$true)]
            [string]$NewConnectorName,
        [Parameter(Mandatory=$true)]
            [string]$ServerURL,
        [Parameter(Mandatory=$true)]
            [string]$AccessKey,
        [Parameter(Mandatory=$true)]
            [string]$SecretKey,
        [Parameter(Mandatory=$false)]
            [int]$RepositoryID,
        [Parameter(Mandatory=$false)]
            [string]$RepositoryName,
        [Parameter(Mandatory=$false)]
            [string]$AssetID
    )
    
    # 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 Tenable.sc $NewConnectorName
    $ConnectorID = $ConnectorInfo.id
    
    # Update the blank tool connector with the proper configuration info
    $uri = $CDXSERVER + "/x/tool-connector-config/values/" + $ConnectorID

    If($RefreshTime -ne "") {
        $RefreshInterval = @{ daily = $RefreshTime }
    }else {
        $RefreshInterval = $false
    }
    
    $RepoInfo = [pscustomobject]@{
        'id' = $RepositoryID
        'name' = $RepositoryName
    }

    $IntervalInfo = [pscustomobject]@{
        'daily' = '01:00'
    }

    $nothing = ""
    
    $body = ConvertTo-Json @{
        'server-host' = $ServerURL
        'access-key' = $AccessKey
        'tenable_severity_type_Info' = $true
        'tenable_severity_type_Low' = $true
        'tenable_severity_type_Medium' = $true
        'tenable_severity_type_High' = $true
        'tenable_severity_type_Critical' = $true
        'last-seen' = '0:30'
        'auto-refresh-interval' = $IntervalInfo
        'secret-key' = $SecretKey
        'repository' = $RepoInfo
        'asset' = $AssetID
        'ip' = $nothing
        'dns' = $nothing
    }

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

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

}