public/Get-NexposeVulnerabilityException.ps1

Function Get-NexposeVulnerabilityException {
<#
    .SYNOPSIS
        Returns the specified vulnerability exception
 
    .DESCRIPTION
        Returns the specified vulnerability exception
 
    .PARAMETER Id
        The identifier if the exception
 
    .PARAMETER SubmittedBy
        Filter all exceptions by the submitted user
 
    .PARAMETER ReviewedBy
        Filter all exceptions by the reviewing user
 
    .PARAMETER State
        Filter all exceptions by the approval state
 
    .EXAMPLE
        Get-NexposeVulnerabilityException -Id 42
 
    .EXAMPLE
        Get-NexposeVulnerabilityException -SubmittedBy 'JoeB' -State 'Approved'
 
    .NOTES
        For additional information please see my GitHub wiki page
 
    .FUNCTIONALITY
        GET: vulnerability_exceptions
        GET: vulnerability_exceptions/{id}
        GET: SKIPPED - vulnerability_exceptions/{id}/expires
 
    .LINK
        https://github.com/My-Random-Thoughts/Rapid7Nexpose
#>


    [CmdletBinding(DefaultParameterSetName = 'byId')]
    Param (
        [Parameter(ParameterSetName = 'byId')]
        [int]$Id = 0,

        [Parameter(ParameterSetName = 'byOther')]
        [string]$SubmittedBy,

        [Parameter(ParameterSetName = 'byOther')]
        [string]$ReviewedBy,

        [Parameter(ParameterSetName = 'byOther')]
        [ValidateSet('Deleted','Expired','Approved','Rejected','Under Review')]
        [string]$State
    )

    Switch ($PSCmdlet.ParameterSetName) {
        'byId' {
            If ($Id -gt 0) {
                Write-Output (Invoke-NexposeQuery -UrlFunction "vulnerability_exceptions/$Id" -RestMethod Get)
            }
            Else {
                Write-Output @(Invoke-NexposeQuery -UrlFunction 'vulnerability_exceptions' -RestMethod Get)    # Return All
            }
        }

        'byOther' {
            $vulnExp = @(Invoke-NexposeQuery -UrlFunction 'vulnerability_exceptions' -RestMethod Get)

            If ([string]::IsNullOrEmpty($SubmittedBy) -eq $false) {
                [int]$UserSId = (ConvertTo-NexposeId -Name $SubmittedBy -ObjectType User)
                $vulnExp = ($vulnExp | Where-Object { $_.submit.user -eq $UserSId })
            }

            If ([string]::IsNullOrEmpty($ReviewedBy) -eq $false) {
                [int]$UserRId = (ConvertTo-NexposeId -Name $ReviewedBy -ObjectType User)
                $vulnExp = ($vulnExp | Where-Object { $_.review.user -eq $UserRId })
            }

            If ([string]::IsNullOrEmpty($State) -eq $false) {
                $vulnExp = ($vulnExp | Where-Object { $_.state -eq $State })
            }

            Write-Output $vulnExp
        }
    }
}