locked
Automated report generation / catch all issues RRS feed

  • Question

  • I will happily admit PS is not my strongest of suits. I have been tasked with automating some Nessus reporting. The first part of my script works without an issue. It writes the reports correctly with the correct source data out of Nessus. The part I cant seem to wrap my head around is getting the catch all to work. When this part of the script runs it writes a secondary set of reports to the directory not just writing out any of the outliers. 

    Both me and a coworker have tried to get this to work with no success. Please help!

    #Get a list of all completed scans.
    $CompletedScan = Get-NessusScan -SessionId $ID -Status Completed
    #Folder locations for scan exports
    $LDRFolder = "\\server\NessusReports\LDR\"
    $LWCFolder = "\\server\NessusReports\LWC"
    $DCFSFolder = "\\server\NessusReports\DCFS"
    $OTSFolder = "\\server\NessusReports\OTS"
    $zzCatchAll= "\\server\NessusReports\zzCatchAll"
    #Nessus Folder ID Mappings
    $LDRFolderID = "78"
    $LWCFolderID = "79"
    $DCFSFolderID = "80"
    $OTSFolderID = "124"
    #loop through each scan and export the results to CSV
    Foreach ($scan in $CompletedScan) {
    #This is needed as putting $scan.name in the export logic fails (name too long).
    $ScanName = $scan.Name
    #Store scan history for each completed scan (needed for clearing later)
    $ScanHistory = Show-NessusScanHistory -ScanId $scan.ScanID -SessionId $id
    #write the name of each scan exported to the console (can be changed if automated)
    write-host Name: -f "white" -nonewline; write-host $scan.Name -f "black" -backgroundcolor "white"
        #LDR scan exports
        if ($scan.FolderID -eq $LDRFolderID) {
            #Test Scan export subdirectory
            if ($ScanName -like "*Test Scan*") {
            Export-NessusScan -SessionId $ID -ScanId $scan.ScanID -Format CSV -OutFile "$LDRFolder\Test Scan\$ScanName-$date-$time.csv"
            }
            #Microsoft Server vuln scan export subdirectory
            if ($ScanName -like "*MS-Server_Vuln*") {
            Export-NessusScan -SessionId $ID -ScanId $scan.ScanID -Format CSV -OutFile "$LDRFolder\MS-Server_Vuln\$ScanName-$date-$time.csv"
            }
            #Microsoft Server compliance scan export subdirectory
            if ($ScanName -like "*MS-Server*_Compliance*") {
            Export-NessusScan -SessionId $ID -ScanId $scan.ScanID -Format CSV -OutFile "$LDRFolder\MS-Server_Compliance\$ScanName-$date-$time.csv"
            }
            #Network Device vuln scan export subdirectory
            if ($ScanName -like "*NetworkDevice_Vuln*") {
            Export-NessusScan -SessionId $ID -ScanId $scan.ScanID -Format CSV -OutFile "$LDRFolder\NetworkDevice_Vuln\$ScanName-$date-$time.csv"
            }
            #Network Device compliance scan export subdirectory
            if ($ScanName -like "*NetworkDevice_Compliance*") {
            Export-NessusScan -SessionId $ID -ScanId $scan.ScanID -Format CSV -OutFile "$LDRFolder\NetworkDevice_Compliance\$ScanName-$date-$time.csv"
            }
            #Printer vuln scan export subdirectory
            if ($ScanName -like "*Printer_Vuln*") {
            Export-NessusScan -SessionId $ID -ScanId $scan.ScanID -Format CSV -OutFile "$LDRFolder\Printer_Vuln\$ScanName-$date-$time.csv"
            }
        }
        #LWC scan exports
        if ($scan.FolderID -eq $LWCFolderID) {
            #Microsoft Server vuln scan export subdirectory
            if ($ScanName -like "*MS-Server_Vuln*") {
            Export-NessusScan -SessionId $ID -ScanId $scan.ScanID -Format CSV -OutFile "$LWCFolder\MS-Server_Vuln\$ScanName-$date-$time.csv"
            }
            #Microsoft Server compliance scan export subdirectory
            if ($ScanName -like "*MS-Server*_Compliance*") {
            Export-NessusScan -SessionId $ID -ScanId $scan.ScanID -Format CSV -OutFile "$LWCFolder\MS-Server_Compliance\$ScanName-$date-$time.csv"
            }
            #Network Device vuln scan export subdirectory
            if ($ScanName -like "*NetworkDevice_Vuln*") {
            Export-NessusScan -SessionId $ID -ScanId $scan.ScanID -Format CSV -OutFile "$LWCFolder\NetworkDevice_Vuln\$ScanName-$date-$time.csv"
            }
            #Network Device compliance scan export subdirectory
            if ($ScanName -like "*NetworkDevice_Compliance*") {
            Export-NessusScan -SessionId $ID -ScanId $scan.ScanID -Format CSV -OutFile "$LWCFolder\NetworkDevice_Compliance\$ScanName-$date-$time.csv"
            }
            #Printer vuln scan export subdirectory
            if ($ScanName -like "*Printer_Vuln*") {
            Export-NessusScan -SessionId $ID -ScanId $scan.ScanID -Format CSV -OutFile "$DCFSFolder\Printer_Vuln\$ScanName-$date-$time.csv"
            }
        }
        #DCFS scan export
        if ($scan.FolderID -eq $DCFSFolderID) {
                #Microsoft Server vuln scan export subdirectory
            if ($ScanName -like "*MS-Server_Vuln*") {
            Export-NessusScan -SessionId $ID -ScanId $scan.ScanID -Format CSV -OutFile "$DCFSFolder\MS-Server_Vuln\$ScanName-$date-$time.csv"
            }
            #Microsoft Server compliance scan export subdirectory
            if ($ScanName -like "*MS-Server*_Compliance*") {
            Export-NessusScan -SessionId $ID -ScanId $scan.ScanID -Format CSV -OutFile "$DCFSFolder\MS-Server_Compliance\$ScanName-$date-$time.csv"
            }
            #SuSEv11 vuln scan export subdirectory
            if ($ScanName -like "*SuSEv11_Vuln*") {
            Export-NessusScan -SessionId $ID -ScanId $scan.ScanID -Format CSV -OutFile "$DCFSFolder\SuSEv11_Vuln\$ScanName-$date-$time.csv"
            }
            #SuSEv11 vuln scan export subdirectory
            if ($ScanName -like "*SuSEv11_Compliance*") {
            Export-NessusScan -SessionId $ID -ScanId $scan.ScanID -Format CSV -OutFile "$DCFSFolder\SuSEv11_Compliance\$ScanName-$date-$time.csv"
            }
            #Network Device vuln scan export subdirectory
            if ($ScanName -like "*NetworkDevice_Vuln*") {
            Export-NessusScan -SessionId $ID -ScanId $scan.ScanID -Format CSV -OutFile "$DCFSFolder\NetworkDevice_Vuln\$ScanName-$date-$time.csv"
            }
            #Network Device compliance scan export subdirectory
            if ($ScanName -like "*NetworkDevice_Compliance*") {
            Export-NessusScan -SessionId $ID -ScanId $scan.ScanID -Format CSV -OutFile "$DCFSFolder\NetworkDevice_Compliance\$ScanName-$date-$time.csv"
            }
            #Printer vuln scan export subdirectory
            if ($ScanName -like "*Printer_Vuln*") {
            Export-NessusScan -SessionId $ID -ScanId $scan.ScanID -Format CSV -OutFile "$DCFSFolder\Printer_Vuln\$ScanName-$date-$time.csv"
            }
        }
        #OTS scan export
        if ($scan.FolderID -eq $OTSFolderID) {
            #Network Device vuln scan export subdirectory
            if ($ScanName -like "*FortiGate_Vuln*") {
            Export-NessusScan -SessionId $ID -ScanId $scan.ScanID -Format CSV -OutFile "$OTSFolder\NetworkDevice_Vuln\$ScanName-$date-$time.csv"
            }
        }
        #Catch All for any report not coded with a destination (i.e. new reports)
        Else ($scan.FolderID -ne ($OTSFolderID -or $DCFSFolderID -or $LWCFolderID -or $LDRFolderID)) {
            Export-NessusScan -SessionID $ID -ScanID $scan.ScanID -Format CSV -OutFile "$zzCatchAll\$ScanName-$date-$time.csv"

        }

        <#
        #Gotta be a try / catch in case there is no scan history on the selected scan
        Try {
            #Loop through the different scan histories and clear them
            Foreach ($Entry in $ScanHistory.HistoryID) {
            Remove-NessusScanHistory -ScanID $scan.ScanID -SessionID $ID -Historyid $Entry -ErrorAction SilentlyContinue
            }
        }

        Catch [Exception] {
        }
    #>
    }

    Monday, December 4, 2017 4:49 PM

Answers

  • These $scan.folderID attributes would only apply to 1 scan report at a time, correct? i.e.

    $scan.FolderID would equal LDR OR LWC OR ..., not multiple.

    If that's the case, let's change this to if/elseif statements and end with an else statement. That way it picks up anything that hasn't been matched already. Speeds up your script as well:

    #Get a list of all completed scans.
    $CompletedScan = Get-NessusScan -SessionId $ID -Status Completed
    #Folder locations for scan exports
    $LDRFolder = "\\server\NessusReports\LDR\"
    $LWCFolder = "\\server\NessusReports\LWC"
    $DCFSFolder = "\\server\NessusReports\DCFS"
    $OTSFolder = "\\server\NessusReports\OTS"
    $zzCatchAll= "\\server\NessusReports\zzCatchAll"
    #Nessus Folder ID Mappings
    $LDRFolderID = "78"
    $LWCFolderID = "79"
    $DCFSFolderID = "80"
    $OTSFolderID = "124"
    #loop through each scan and export the results to CSV
    Foreach ($scan in $CompletedScan) {
    #This is needed as putting $scan.name in the export logic fails (name too long).
    $ScanName = $scan.Name
    #Store scan history for each completed scan (needed for clearing later)
    $ScanHistory = Show-NessusScanHistory -ScanId $scan.ScanID -SessionId $id
    #write the name of each scan exported to the console (can be changed if automated)
    write-host Name: -f "white" -nonewline; write-host $scan.Name -f "black" -backgroundcolor "white"
        #LDR scan exports
        if ($scan.FolderID -eq $LDRFolderID) {
            #Test Scan export subdirectory
            if ($ScanName -like "*Test Scan*") {
            Export-NessusScan -SessionId $ID -ScanId $scan.ScanID -Format CSV -OutFile "$LDRFolder\Test Scan\$ScanName-$date-$time.csv"
            }
            #Microsoft Server vuln scan export subdirectory
            if ($ScanName -like "*MS-Server_Vuln*") {
            Export-NessusScan -SessionId $ID -ScanId $scan.ScanID -Format CSV -OutFile "$LDRFolder\MS-Server_Vuln\$ScanName-$date-$time.csv"
            }
            #Microsoft Server compliance scan export subdirectory
            if ($ScanName -like "*MS-Server*_Compliance*") {
            Export-NessusScan -SessionId $ID -ScanId $scan.ScanID -Format CSV -OutFile "$LDRFolder\MS-Server_Compliance\$ScanName-$date-$time.csv"
            }
            #Network Device vuln scan export subdirectory
            if ($ScanName -like "*NetworkDevice_Vuln*") {
            Export-NessusScan -SessionId $ID -ScanId $scan.ScanID -Format CSV -OutFile "$LDRFolder\NetworkDevice_Vuln\$ScanName-$date-$time.csv"
            }
            #Network Device compliance scan export subdirectory
            if ($ScanName -like "*NetworkDevice_Compliance*") {
            Export-NessusScan -SessionId $ID -ScanId $scan.ScanID -Format CSV -OutFile "$LDRFolder\NetworkDevice_Compliance\$ScanName-$date-$time.csv"
            }
            #Printer vuln scan export subdirectory
            if ($ScanName -like "*Printer_Vuln*") {
            Export-NessusScan -SessionId $ID -ScanId $scan.ScanID -Format CSV -OutFile "$LDRFolder\Printer_Vuln\$ScanName-$date-$time.csv"
            }
        }
        #LWC scan exports
        elseif ($scan.FolderID -eq $LWCFolderID) {
            #Microsoft Server vuln scan export subdirectory
            if ($ScanName -like "*MS-Server_Vuln*") {
            Export-NessusScan -SessionId $ID -ScanId $scan.ScanID -Format CSV -OutFile "$LWCFolder\MS-Server_Vuln\$ScanName-$date-$time.csv"
            }
            #Microsoft Server compliance scan export subdirectory
            if ($ScanName -like "*MS-Server*_Compliance*") {
            Export-NessusScan -SessionId $ID -ScanId $scan.ScanID -Format CSV -OutFile "$LWCFolder\MS-Server_Compliance\$ScanName-$date-$time.csv"
            }
            #Network Device vuln scan export subdirectory
            if ($ScanName -like "*NetworkDevice_Vuln*") {
            Export-NessusScan -SessionId $ID -ScanId $scan.ScanID -Format CSV -OutFile "$LWCFolder\NetworkDevice_Vuln\$ScanName-$date-$time.csv"
            }
            #Network Device compliance scan export subdirectory
            if ($ScanName -like "*NetworkDevice_Compliance*") {
            Export-NessusScan -SessionId $ID -ScanId $scan.ScanID -Format CSV -OutFile "$LWCFolder\NetworkDevice_Compliance\$ScanName-$date-$time.csv"
            }
            #Printer vuln scan export subdirectory
            if ($ScanName -like "*Printer_Vuln*") {
            Export-NessusScan -SessionId $ID -ScanId $scan.ScanID -Format CSV -OutFile "$DCFSFolder\Printer_Vuln\$ScanName-$date-$time.csv"
            }
        }
        #DCFS scan export
        elseif ($scan.FolderID -eq $DCFSFolderID) {
                #Microsoft Server vuln scan export subdirectory
            if ($ScanName -like "*MS-Server_Vuln*") {
            Export-NessusScan -SessionId $ID -ScanId $scan.ScanID -Format CSV -OutFile "$DCFSFolder\MS-Server_Vuln\$ScanName-$date-$time.csv"
            }
            #Microsoft Server compliance scan export subdirectory
            if ($ScanName -like "*MS-Server*_Compliance*") {
            Export-NessusScan -SessionId $ID -ScanId $scan.ScanID -Format CSV -OutFile "$DCFSFolder\MS-Server_Compliance\$ScanName-$date-$time.csv"
            }
            #SuSEv11 vuln scan export subdirectory
            if ($ScanName -like "*SuSEv11_Vuln*") {
            Export-NessusScan -SessionId $ID -ScanId $scan.ScanID -Format CSV -OutFile "$DCFSFolder\SuSEv11_Vuln\$ScanName-$date-$time.csv"
            }
            #SuSEv11 vuln scan export subdirectory
            if ($ScanName -like "*SuSEv11_Compliance*") {
            Export-NessusScan -SessionId $ID -ScanId $scan.ScanID -Format CSV -OutFile "$DCFSFolder\SuSEv11_Compliance\$ScanName-$date-$time.csv"
            }
            #Network Device vuln scan export subdirectory
            if ($ScanName -like "*NetworkDevice_Vuln*") {
            Export-NessusScan -SessionId $ID -ScanId $scan.ScanID -Format CSV -OutFile "$DCFSFolder\NetworkDevice_Vuln\$ScanName-$date-$time.csv"
            }
            #Network Device compliance scan export subdirectory
            if ($ScanName -like "*NetworkDevice_Compliance*") {
            Export-NessusScan -SessionId $ID -ScanId $scan.ScanID -Format CSV -OutFile "$DCFSFolder\NetworkDevice_Compliance\$ScanName-$date-$time.csv"
            }
            #Printer vuln scan export subdirectory
            if ($ScanName -like "*Printer_Vuln*") {
            Export-NessusScan -SessionId $ID -ScanId $scan.ScanID -Format CSV -OutFile "$DCFSFolder\Printer_Vuln\$ScanName-$date-$time.csv"
            }
        }
        #OTS scan export
        elseif ($scan.FolderID -eq $OTSFolderID) {
            #Network Device vuln scan export subdirectory
            if ($ScanName -like "*FortiGate_Vuln*") {
            Export-NessusScan -SessionId $ID -ScanId $scan.ScanID -Format CSV -OutFile "$OTSFolder\NetworkDevice_Vuln\$ScanName-$date-$time.csv"
            }
        }
        #Catch All for any report not coded with a destination (i.e. new reports)
        Else{
            Export-NessusScan -SessionID $ID -ScanID $scan.ScanID -Format CSV -OutFile "$zzCatchAll\$ScanName-$date-$time.csv"
    
        }
    
        <#
        #Gotta be a try / catch in case there is no scan history on the selected scan
        Try {
            #Loop through the different scan histories and clear them
            Foreach ($Entry in $ScanHistory.HistoryID) {
            Remove-NessusScanHistory -ScanID $scan.ScanID -SessionID $ID -Historyid $Entry -ErrorAction SilentlyContinue
            }
        }
    
        Catch [Exception] {
        }
    #>
    }


    Jeremy Corbello | https://www.jeremycorbello.com

    • Marked as answer by TheMetal1123 Monday, December 4, 2017 9:59 PM
    Monday, December 4, 2017 7:16 PM

All replies

  • Here's where your issue is:

    #OTS scan export
        if ($scan.FolderID -eq $OTSFolderID) {
            #Network Device vuln scan export subdirectory
            if ($ScanName -like "*FortiGate_Vuln*") {
            Export-NessusScan -SessionId $ID -ScanId $scan.ScanID -Format CSV -OutFile "$OTSFolder\NetworkDevice_Vuln\$ScanName-$date-$time.csv"
            }
        }
        #Catch All for any report not coded with a destination (i.e. new reports)
        Else ($scan.FolderID -ne ($OTSFolderID -or $DCFSFolderID -or $LWCFolderID -or $LDRFolderID)) {
            Export-NessusScan -SessionID $ID -ScanID $scan.ScanID -Format CSV -OutFile "$zzCatchAll\$ScanName-$date-$time.csv"
    
        }

    The Else statement doesn't allow a qualifier like the If statement does. i.e.:

    if (condition) {statement}
    elseif (condition) {statement}
    else {statement}

    Else is already in essence a catch-all. 

    What you probably want to do is use another If statement where the Else statement is at:

    If ($scan.FolderID -ne ($OTSFolderID -or $DCFSFolderID -or $LWCFolderID -or $LDRFolderID)) {
            Export-NessusScan -SessionID $ID -ScanID $scan.ScanID -Format CSV -OutFile "$zzCatchAll\$ScanName-$date-$time.csv"
    
        }
    Since you already have the conditions in place to pick up the stragglers, should do what you need.


    Jeremy Corbello | https://www.jeremycorbello.com

    Monday, December 4, 2017 6:18 PM
  • Thank you so much! I will give it a go once I get back!
    Monday, December 4, 2017 6:34 PM
  • No dice man. Same result. Its still writing all reports to the zzCatchAll Directory.
    Monday, December 4, 2017 7:11 PM
  • These $scan.folderID attributes would only apply to 1 scan report at a time, correct? i.e.

    $scan.FolderID would equal LDR OR LWC OR ..., not multiple.

    If that's the case, let's change this to if/elseif statements and end with an else statement. That way it picks up anything that hasn't been matched already. Speeds up your script as well:

    #Get a list of all completed scans.
    $CompletedScan = Get-NessusScan -SessionId $ID -Status Completed
    #Folder locations for scan exports
    $LDRFolder = "\\server\NessusReports\LDR\"
    $LWCFolder = "\\server\NessusReports\LWC"
    $DCFSFolder = "\\server\NessusReports\DCFS"
    $OTSFolder = "\\server\NessusReports\OTS"
    $zzCatchAll= "\\server\NessusReports\zzCatchAll"
    #Nessus Folder ID Mappings
    $LDRFolderID = "78"
    $LWCFolderID = "79"
    $DCFSFolderID = "80"
    $OTSFolderID = "124"
    #loop through each scan and export the results to CSV
    Foreach ($scan in $CompletedScan) {
    #This is needed as putting $scan.name in the export logic fails (name too long).
    $ScanName = $scan.Name
    #Store scan history for each completed scan (needed for clearing later)
    $ScanHistory = Show-NessusScanHistory -ScanId $scan.ScanID -SessionId $id
    #write the name of each scan exported to the console (can be changed if automated)
    write-host Name: -f "white" -nonewline; write-host $scan.Name -f "black" -backgroundcolor "white"
        #LDR scan exports
        if ($scan.FolderID -eq $LDRFolderID) {
            #Test Scan export subdirectory
            if ($ScanName -like "*Test Scan*") {
            Export-NessusScan -SessionId $ID -ScanId $scan.ScanID -Format CSV -OutFile "$LDRFolder\Test Scan\$ScanName-$date-$time.csv"
            }
            #Microsoft Server vuln scan export subdirectory
            if ($ScanName -like "*MS-Server_Vuln*") {
            Export-NessusScan -SessionId $ID -ScanId $scan.ScanID -Format CSV -OutFile "$LDRFolder\MS-Server_Vuln\$ScanName-$date-$time.csv"
            }
            #Microsoft Server compliance scan export subdirectory
            if ($ScanName -like "*MS-Server*_Compliance*") {
            Export-NessusScan -SessionId $ID -ScanId $scan.ScanID -Format CSV -OutFile "$LDRFolder\MS-Server_Compliance\$ScanName-$date-$time.csv"
            }
            #Network Device vuln scan export subdirectory
            if ($ScanName -like "*NetworkDevice_Vuln*") {
            Export-NessusScan -SessionId $ID -ScanId $scan.ScanID -Format CSV -OutFile "$LDRFolder\NetworkDevice_Vuln\$ScanName-$date-$time.csv"
            }
            #Network Device compliance scan export subdirectory
            if ($ScanName -like "*NetworkDevice_Compliance*") {
            Export-NessusScan -SessionId $ID -ScanId $scan.ScanID -Format CSV -OutFile "$LDRFolder\NetworkDevice_Compliance\$ScanName-$date-$time.csv"
            }
            #Printer vuln scan export subdirectory
            if ($ScanName -like "*Printer_Vuln*") {
            Export-NessusScan -SessionId $ID -ScanId $scan.ScanID -Format CSV -OutFile "$LDRFolder\Printer_Vuln\$ScanName-$date-$time.csv"
            }
        }
        #LWC scan exports
        elseif ($scan.FolderID -eq $LWCFolderID) {
            #Microsoft Server vuln scan export subdirectory
            if ($ScanName -like "*MS-Server_Vuln*") {
            Export-NessusScan -SessionId $ID -ScanId $scan.ScanID -Format CSV -OutFile "$LWCFolder\MS-Server_Vuln\$ScanName-$date-$time.csv"
            }
            #Microsoft Server compliance scan export subdirectory
            if ($ScanName -like "*MS-Server*_Compliance*") {
            Export-NessusScan -SessionId $ID -ScanId $scan.ScanID -Format CSV -OutFile "$LWCFolder\MS-Server_Compliance\$ScanName-$date-$time.csv"
            }
            #Network Device vuln scan export subdirectory
            if ($ScanName -like "*NetworkDevice_Vuln*") {
            Export-NessusScan -SessionId $ID -ScanId $scan.ScanID -Format CSV -OutFile "$LWCFolder\NetworkDevice_Vuln\$ScanName-$date-$time.csv"
            }
            #Network Device compliance scan export subdirectory
            if ($ScanName -like "*NetworkDevice_Compliance*") {
            Export-NessusScan -SessionId $ID -ScanId $scan.ScanID -Format CSV -OutFile "$LWCFolder\NetworkDevice_Compliance\$ScanName-$date-$time.csv"
            }
            #Printer vuln scan export subdirectory
            if ($ScanName -like "*Printer_Vuln*") {
            Export-NessusScan -SessionId $ID -ScanId $scan.ScanID -Format CSV -OutFile "$DCFSFolder\Printer_Vuln\$ScanName-$date-$time.csv"
            }
        }
        #DCFS scan export
        elseif ($scan.FolderID -eq $DCFSFolderID) {
                #Microsoft Server vuln scan export subdirectory
            if ($ScanName -like "*MS-Server_Vuln*") {
            Export-NessusScan -SessionId $ID -ScanId $scan.ScanID -Format CSV -OutFile "$DCFSFolder\MS-Server_Vuln\$ScanName-$date-$time.csv"
            }
            #Microsoft Server compliance scan export subdirectory
            if ($ScanName -like "*MS-Server*_Compliance*") {
            Export-NessusScan -SessionId $ID -ScanId $scan.ScanID -Format CSV -OutFile "$DCFSFolder\MS-Server_Compliance\$ScanName-$date-$time.csv"
            }
            #SuSEv11 vuln scan export subdirectory
            if ($ScanName -like "*SuSEv11_Vuln*") {
            Export-NessusScan -SessionId $ID -ScanId $scan.ScanID -Format CSV -OutFile "$DCFSFolder\SuSEv11_Vuln\$ScanName-$date-$time.csv"
            }
            #SuSEv11 vuln scan export subdirectory
            if ($ScanName -like "*SuSEv11_Compliance*") {
            Export-NessusScan -SessionId $ID -ScanId $scan.ScanID -Format CSV -OutFile "$DCFSFolder\SuSEv11_Compliance\$ScanName-$date-$time.csv"
            }
            #Network Device vuln scan export subdirectory
            if ($ScanName -like "*NetworkDevice_Vuln*") {
            Export-NessusScan -SessionId $ID -ScanId $scan.ScanID -Format CSV -OutFile "$DCFSFolder\NetworkDevice_Vuln\$ScanName-$date-$time.csv"
            }
            #Network Device compliance scan export subdirectory
            if ($ScanName -like "*NetworkDevice_Compliance*") {
            Export-NessusScan -SessionId $ID -ScanId $scan.ScanID -Format CSV -OutFile "$DCFSFolder\NetworkDevice_Compliance\$ScanName-$date-$time.csv"
            }
            #Printer vuln scan export subdirectory
            if ($ScanName -like "*Printer_Vuln*") {
            Export-NessusScan -SessionId $ID -ScanId $scan.ScanID -Format CSV -OutFile "$DCFSFolder\Printer_Vuln\$ScanName-$date-$time.csv"
            }
        }
        #OTS scan export
        elseif ($scan.FolderID -eq $OTSFolderID) {
            #Network Device vuln scan export subdirectory
            if ($ScanName -like "*FortiGate_Vuln*") {
            Export-NessusScan -SessionId $ID -ScanId $scan.ScanID -Format CSV -OutFile "$OTSFolder\NetworkDevice_Vuln\$ScanName-$date-$time.csv"
            }
        }
        #Catch All for any report not coded with a destination (i.e. new reports)
        Else{
            Export-NessusScan -SessionID $ID -ScanID $scan.ScanID -Format CSV -OutFile "$zzCatchAll\$ScanName-$date-$time.csv"
    
        }
    
        <#
        #Gotta be a try / catch in case there is no scan history on the selected scan
        Try {
            #Loop through the different scan histories and clear them
            Foreach ($Entry in $ScanHistory.HistoryID) {
            Remove-NessusScanHistory -ScanID $scan.ScanID -SessionID $ID -Historyid $Entry -ErrorAction SilentlyContinue
            }
        }
    
        Catch [Exception] {
        }
    #>
    }


    Jeremy Corbello | https://www.jeremycorbello.com

    • Marked as answer by TheMetal1123 Monday, December 4, 2017 9:59 PM
    Monday, December 4, 2017 7:16 PM
  • Thanks man! Worked like a charm!
    Monday, December 4, 2017 10:00 PM