public/Update-NexposeVulnerabilityException.ps1

Function Update-NexposeVulnerabilityException {
<#
    .SYNOPSIS
        Update the status of the vulnerability exception
 
    .DESCRIPTION
        Update the status of the vulnerability exception
 
    .PARAMETER Id
        The identifier of the exception
 
    .PARAMETER State
        Exception Status. Valid values:"recall" "approve" "reject"
 
    .PARAMETER Comment
        Reviewers comments for this state change
 
    .PARAMETER NewExpiryDate
        Specify the new expiry date for the exception
 
    .EXAMPLE
        Update-NexposeVulnerabilityException -Id 24 -State approve -Comment 'All OK'
 
    .NOTES
        For additional information please see my GitHub wiki page
 
    .FUNCTIONALITY
        GET: vulnerability_exceptions/{id}
        PUT: vulnerability_exceptions/{id}/expires
        POST: vulnerability_exceptions/{id}/{status}
 
    .LINK
        https://github.com/My-Random-Thoughts/Rapid7Nexpose
#>


    [CmdletBinding(DefaultParameterSetName = 'byId', SupportsShouldProcess)]
    Param (
        [Parameter(Mandatory = $true, ParameterSetName = 'byId')]
        [Parameter(Mandatory = $true, ParameterSetName = 'byState')]
        [int]$Id,

        [Parameter(Mandatory = $true, ParameterSetName = 'byState')]
        [ValidateSet('recall','approve','reject')]
        [string]$State,

        [Parameter(ParameterSetName = 'byState' )]
        [string]$Comment = "State changed by $($env:UserName)",

        [ValidateScript({ $_ -gt (Get-Date) })]
        [datetime]$NewExpiryDate
    )

    If ($PSCmdlet.ShouldProcess($Id)) {
        # Get current state of exception, ensure it's in a "Under Review" state.
        $CurrentState = (Invoke-NexposeQuery -UrlFunction "vulnerability_exceptions/$Id" -RestMethod Get)

        If ([string]::IsNullOrEmpty($State) -eq $false) {
            If (($CurrentState.State) -eq 'Under Review') {
                Write-Output (Invoke-NexposeQuery -UrlFunction "vulnerability_exceptions/$Id/$State" -ApiQuery "$Comment" -RestMethod Post)
            }
        }

        If ([string]::IsNullOrEmpty($NewExpiryDate) -eq $false) {
            [string]$apiQuery = "$($NewExpiryDate.ToString('yyyy-MM-dd'))T23:59:59.999Z"
            Write-Output (Invoke-NexposeQuery -UrlFunction "vulnerability_exceptions/$Id/expires" -ApiQuery $apiQuery -RestMethod Put)
        }
    }
}