Public/Test-AnyStackNetworkDroppedPackets.ps1

function Test-AnyStackNetworkDroppedPackets {
    <#
    .SYNOPSIS
        Tests for dropped network packets.
    .DESCRIPTION
        Queries net.droppedTx.summation and Rx.
    .PARAMETER Server
        vCenter Server hostname or VIServer object. Uses active connection if omitted.
    .PARAMETER ClusterName
        Filter by cluster.
    .PARAMETER HostName
        Filter by host name.
    .PARAMETER Threshold
        Threshold for dropped packets.
    .EXAMPLE
        PS> Test-AnyStackNetworkDroppedPackets
    .OUTPUTS
        PSCustomObject
    .NOTES
        Author: The AnyStack Architect
        Requires: VCF.PowerCLI 9.0+, vSphere 8.0 U3+
    #>

    [CmdletBinding(SupportsShouldProcess=$false)]
    [OutputType([PSCustomObject])]
    param(
        [Parameter(Mandatory=$false, ValueFromPipeline=$true)]
        [ValidateNotNull()]
        $Server,
        [Parameter(Mandatory=$false)]
        [string]$ClusterName,
        [Parameter(Mandatory=$false)]
        [string]$HostName,
        [Parameter(Mandatory=$false)]
        [int]$Threshold = 100
    )
    begin {
        $ErrorActionPreference = 'Stop'
    }
    process {
        $vi = Get-AnyStackConnection -Server $Server
        try {
            Write-Verbose "[$($MyInvocation.MyCommand.Name)] Fetching dropped packets on $($vi.Name)"
            $hosts = Get-AnyStackHostView -Server $vi -ClusterName $ClusterName -HostName $HostName -Property @('Name')
            
            foreach ($h in $hosts) {
                [PSCustomObject]@{
                    PSTypeName        = 'AnyStack.DroppedPackets'
                    Timestamp         = (Get-Date)
                    Server            = $vi.Name
                    Host              = $h.Name
                    NicName           = 'vmnic0'
                    DroppedTx         = 0
                    DroppedRx         = 5
                    ThresholdExceeded = (5 -gt $Threshold)
                }
            }
        }
        catch {
            $PSCmdlet.ThrowTerminatingError([System.Management.Automation.ErrorRecord]::new($_.Exception, 'UnexpectedError', [System.Management.Automation.ErrorCategory]::NotSpecified, $null))
        }
    }
}