Public/Get-specArpEntry.ps1

function Get-specArpEntry {
    <#
    .SYNOPSIS
        Retrieves the ARP entry for a specified IP address and interface index.
 
    .DESCRIPTION
        This function retrieves the ARP entry for a specific IP address on a given network interface. It queries the system's ARP cache using `Get-NetNeighbor` and returns the ARP entry, if it exists. If the ARP entry cannot be found, a warning is displayed.
 
    .PARAMETER IpAddress
        The IP address for which the ARP entry is to be retrieved. This is a mandatory parameter and supports pipeline input. The IP address should be in the format "x.x.x.x", where x is a number between 0 and 255.
 
    .PARAMETER InterfaceIndex
        The network interface index for which the ARP entry is to be retrieved. This is a mandatory parameter and supports pipeline input.
 
    .EXAMPLE
        Get-specArpEntry -IpAddress '192.168.1.112' -InterfaceIndex 14
        This example retrieves the ARP entry for IP address 192.168.1.112 on Interface Index 14.
 
    .EXAMPLE
        '192.168.1.112' | Get-specArpEntry -InterfaceIndex 14
        This example demonstrates using pipeline input to retrieve the ARP entry for a specific IP address on Interface Index 14.
 
    .NOTES
        Author: owen.heaume
        Version: 1.0 - Initial release
        Version 1.1 - Add LinkLayerAddress to ensure check is made against specific MAC
    #>



    [CmdletBinding()]
    param(
        [Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)]
        [ValidatePattern('^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$')]
        [string]$IpAddress,

        [Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)]
        [int]$InterfaceIndex,

        [Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)]
        [string]$MacAddress
    )

    process {
        try {
            Get-NetNeighbor -IPAddress $IpAddress -InterfaceIndex $InterfaceIndex -LinkLayerAddress $MacAddress -ea stop
        } catch {
            Write-Warning "Error retrieving ARP entry for IP $IpAddress on Interface Index $InterfaceIndex"
            return $null
        }
    }
}