functions/Import-TenableSCFromCSV.ps1

<#
.SYNOPSIS
Create tenable SC connectors based on a CSV file to be imported.
  
.DESCRIPTION
Used to create projects with tenable SC connectors, based upon an imported CSV file.
  
.EXAMPLE
Import-TenableSCFromCSV .\myfile.csv
  
#>


Function Import-TenableSCFromCSV
{
    [cmdletbinding()]
    param(
        [Parameter(Mandatory=$true)]
        [string]$CSVFilePath
    )
    
    $CSVArray = Import-Csv $CSVFilePath
    
    $CSVArray | ForEach-Object{
        # Keeping these as separate variables in case we'd like to make them independent or add a prefix later
        $ProjectName = $_.CodeDxProjectName
        $NewConnectorName = $_.ConfigName
        $ToolHostURL = $_.ServerURL
        $AccessKey = $_.AccessKey
        $SecretKey = $_.SecretKey
        $RepoID = $_.RepoID
        $RepoName = $_.RepoName
        $AssetID = $_.AssetID
        $ParentProject = $_.ParentProject
        
        # Check for Project existence. If not there, create it.
        $SourcePID = $null
        $SourcePID = Get-ProjectID $ProjectName
        If($SourcePID.length -eq 0){
            $arrSourcePID = Add-Project $ProjectName
            $SourcePID = arrSourcePID[0]
        }
        
        #Move Project into parent.
        Set-ProjectParent $SourcePID $ParentProject

        $CreateConnector = Add-TenableSCConnector $ProjectName $NewConnectorName $ToolHostURL $AccessKey $SecretKey $RepoID $RepoName $AssetID
        Write-Verbose ( $CreateConnector | Format-Table | Out-String )
    }

}