Public/Get-HealthMonitor.ps1

Function Get-HealthMonitor {
<#
.SYNOPSIS
    Retrieve specified health monitor(s)
.NOTES
    Health monitor names are case-specific.
#>

    [cmdletBinding()]
    param (
        $F5Session=$Script:F5Session,

        [Alias('MonitorName')]
        [Parameter(Mandatory=$false,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true)]
        [string[]]$Name='',

        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [string]$Partition,
        
        [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true)]
        [string[]]$Type
    )
    begin {
        #Test that the F5 session is in a valid format
        Test-F5Session($F5Session)

        Write-Verbose "NB: Health monitor names are case-specific."
        $TypeSearchErrorAction = $ErrorActionPreference
        if ([string]::IsNullOrEmpty($Type)) {
            $TypeSearchErrorAction = 'SilentlyContinue'
            $Type = Get-HealthMonitorType -F5Session $F5Session
        }
    }
    process {
        foreach ($typename in $Type) {
            foreach ($itemname in $Name) {
                $URI = $F5Session.BaseURL + 'monitor/{0}' -f ($typename,(Get-ItemPath -Name $itemname -Partition $Partition) -join '/')
                $JSON = Invoke-RestMethodOverride -Method Get -Uri $URI -Credential $F5Session.Credential -ErrorAction $TypeSearchErrorAction
                if ($JSON.items -or $JSON.name) {
                    Invoke-NullCoalescing {$JSON.items} {$JSON} |
                        Add-ObjectDetail -TypeName 'PoshLTM.HealthMonitor' -PropertyToAdd @{type=$typename}
                }
            }
        }
    }
}