public/Save-TNLatestPluginFile.ps1

function Save-TNLatestPluginFile {
    <#
    .SYNOPSIS
        Saves plugin files from plugins.nessus.org
 
    .DESCRIPTION
        Saves plugin files from plugins.nessus.org
 
 
    .PARAMETER Path
        The Path where the plugins will be downloaded, defaults to current directory
 
        If you use the -ActivationCode parameter, a file named tenable-auth.txt will also be saved
 
        This file contains the username and password you will need to download the plugins
 
    .PARAMETER ActivationCode
        This process requires username and password tokens generated by https://plugins.nessus.org/register.php
 
        If you've already activated your copy, you should have kept the username and password that was generated -- use those with the Credential parameter
 
        If you forgot to keep the username and password or don't yet have an activation code, you can grab a new activation code from: https://www.tenable.com/products/nessus/nessus-essentials
 
    .PARAMETER Credential
        You must enter ActivationCode or Credential
 
        This Credential is not your tenable email and password, it's the two encoded strings generated when you activated your copy of Nessus
 
    .PARAMETER EnableException
        By default, when something goes wrong we try to catch it, interpret it and give you a friendly warning message.
        This avoids overwhelming you with 'sea of red' exceptions, but is inconvenient because it basically disables advanced scripting.
        Using this switch turns this 'nice by default' feature off and enables you to catch exceptions with your own try/catch.
 
    .EXAMPLE
        PS C:\> Save-TNLatestPluginFile -ActivationCode ABCD-1234-DEFG-5757-AB90
 
        Activates the Nessus code, savesa file named tenable-auth.txt to the current directory, then downloads the latest plugins to $pwd\all-2.0.tar.gz
 
    .EXAMPLE
        PS C:\> $cred = Get-Credential 77d3def50110b9c77848550b3bf4eda8
        PS C:\> Save-TNLatestPluginFile -Path C:\temp -Credential $cred
 
        Prompts for the password for 77d3def50110b9c77848550b3bf4eda8 then downloads the latest plugin file to C:\temp\all-2.0.tar.gz
    #>

    [CmdletBinding()]
    param (
        [string]$Path = $PWD,
        [pscredential]$Credential,
        [string]$ActivationCode,
        [switch]$EnableException
    )
    process {
        if (-not $PSBoundParameters.ActivationCode -and -not $PSBoundParameters.Credential) {
            Stop-PSFFunction -EnableException:$EnableException -Message "You must specify either ActivationCode or Credential"
            return
        }

        if ($ActivationCode) {
            $request = Invoke-WebRequest -Uri "https://plugins.nessus.org/register.php?serial=$ActivationCode"

            if ($request.Content -match "SUCCESS") {
                $file = Join-Path $Path -ChildPath "tenable-auth.txt"
                $request.Content | Out-File -FilePath $file
                $username = $request.Content.Split("`n")[1]
                $password = $request.Content.Split("`n")[2]
            } else {
                Stop-PSFFunction -EnableException:$EnableException -Message "Activation result failed: $($request.Content)"
                return
            }
        }

        if ($Credential) {
            $username = $Credential.UserName
            $password = $Credential.GetNetworkCredential().Password
        }

        $outfile = Join-Path $Path -ChildPath "all-2.0.tar.gz"
        $ProgressPreference = "SilentlyContinue"
        Invoke-WebRequest -Uri "https://plugins.nessus.org/v2/nessus.php?f=all-2.0.tar.gz&u=$username&p=$password" -OutFile $outfile

        if ((Test-Path -Path $outfile)) {
            Get-ChildItem -Path $outfile
        }
        if ($file) {
            Get-ChildItem -File $file
        }
    }
}