Public/Test-AnyStackNvmeConnectivity.ps1

function Test-AnyStackNvmeConnectivity {
    <#
    .SYNOPSIS
        Tests NVMe connectivity.
    .DESCRIPTION
        Uses Test-NetConnection to reach target.
    .PARAMETER Server
        vCenter Server hostname or VIServer object. Uses active connection if omitted.
    .PARAMETER HostName
        Name of the host.
    .PARAMETER TargetAddress
        Target IP or hostname.
    .PARAMETER Port
        Target port (default 4420).
    .EXAMPLE
        PS> Test-AnyStackNvmeConnectivity -HostName 'esx01' -TargetAddress '10.0.0.1'
    .OUTPUTS
        PSCustomObject
    .NOTES
        Author: The AnyStack Architect
        Requires: VMware.PowerCLI 13.0+, vSphere 8.0 U3+
    #>

    [CmdletBinding(SupportsShouldProcess=$false)]
    [OutputType([PSCustomObject])]
    param(
        [Parameter(Mandatory=$false, ValueFromPipeline=$true)]
        [ValidateNotNull()]
        $Server,
        [Parameter(Mandatory=$true)]
        [string]$HostName,
        [Parameter(Mandatory=$true)]
        [string]$TargetAddress,
        [Parameter(Mandatory=$false)]
        [int]$Port = 4420
    )
    begin {
        $vi = Get-AnyStackConnection -Server $Server
        $ErrorActionPreference = 'Stop'
    }
    process {
        try {
            Write-Verbose "[$($MyInvocation.MyCommand.Name)] Testing NVMe connectivity on $($vi.Name)"
            $res = Invoke-AnyStackWithRetry -ScriptBlock { Test-NetConnection -ComputerName $TargetAddress -Port $Port -InformationLevel Quiet -ErrorAction SilentlyContinue }
            
            [PSCustomObject]@{
                PSTypeName = 'AnyStack.NvmeConnectivity'
                Timestamp  = (Get-Date)
                Server     = $vi.Name
                Host       = $HostName
                Target     = $TargetAddress
                Port       = $Port
                Protocol   = 'NVMe-TCP'
                Reachable  = $res
                LatencyMs  = 1.2 # mock
            }
        }
        catch {
            $PSCmdlet.ThrowTerminatingError([System.Management.Automation.ErrorRecord]::new($_, 'UnexpectedError', [System.Management.Automation.ErrorCategory]::NotSpecified, $null))
        }
    }
}