Public/Get-specNetworkAdapterInfo.ps1

function Get-specNetworkAdapterInfo {
    <#
    .SYNOPSIS
    Retrieves detailed information about network adapters and identifies if each is using Wi-Fi or a wired connection.
 
    .DESCRIPTION
    This function collects detailed information for network adapters. It determines whether each adapter is using Wi-Fi or a wired connection based on its description.
 
    .PARAMETER IncludeDisconnected
    If specified, retrieves information for all network adapters, regardless of connection status.
 
    .OUTPUTS
    PSCustomObject
    Returns a custom object containing details about each network adapter.
 
    .EXAMPLE
    Get-specNetworkAdapterInfo
 
    Retrieves information for all active network adapters.
 
    .EXAMPLE
    Get-specNetworkAdapterInfo -IncludeDisconnected
 
    Retrieves information for all network adapters, including disconnected ones.
 
    .NOTES
    Author: owen.heaume
    Version: 1.0 - Initial release
    #>


    [CmdletBinding()]
    param (
        [Switch]$IncludeDisconnected
    )

    # Determine which network adapters to retrieve based on parameter
    $CurrentNetAdapters = if ($IncludeDisconnected) {
        Get-NetAdapter
    } else {
        Get-NetAdapter | Where-Object { $_.Status -eq 'Up' }
    }

    # Collect network adapter information
    foreach ($CurrentNetAdapter in $CurrentNetAdapters) {
        try {
            # Get IP configuration for the current adapter
            $IPConfiguration = Get-NetIPConfiguration -InterfaceIndex $CurrentNetAdapter.ifIndex -ErrorAction Stop
        } catch {
            $IPConfiguration = $null
        }

        # Check if the adapter is Wi-Fi or Wired
        $isWiFi = ($CurrentNetAdapter.InterfaceDescription -match 'Wi-Fi|Wireless|WiFi' -or $CurrentNetAdapter.InterfaceDescription -match '802.11')
        $ConnectionType = if ($isWiFi) { 'Wi-Fi' } else { 'Wired' }

        [PSCustomObject]@{
            NetInterfaceDescription = $CurrentNetAdapter.InterfaceDescription
            ConnectionType          = $ConnectionType
            NetProfileName          = if ($IPConfiguration) { $IPConfiguration.NetProfile.Name } else { 'N/A' }
            NetIPv4Address          = if ($IPConfiguration) { $IPConfiguration.IPv4Address.IPAddress } else { 'N/A' }
            NetInterfaceAlias       = $CurrentNetAdapter.InterfaceAlias
            NetIPv4DefaultGateway   = if ($IPConfiguration) { $IPConfiguration.IPv4DefaultGateway.NextHop } else { 'N/A' }
            MacAddress              = $CurrentNetAdapter.MacAddress
        }
    }
}