MyITGuy
5/16/2019 - 8:22 PM

Get-WindowsNetworkProvider

#region Get-WindowsNetworkProvider
    function Get-WindowsNetworkProvider {
        [CmdletBinding()]
        PARAM(
            [Parameter(Mandatory = $false, Position = 0, ValueFromPipeline = $true)]
            [string[]]
            $Name
        )

        begin {
            Write-Verbose $MyInvocation.MyCommand
        }

        process {
            $HWOrder = Get-ItemProperty -Path Registry::"HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\NetworkProvider\HWOrder" -ErrorAction SilentlyContinue | Select-Object -ExpandProperty ProviderOrder | Select-Object -First 1 | ForEach-Object {$_ -split ','}
            $Order = Get-ItemProperty -Path Registry::"HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\NetworkProvider\Order" -ErrorAction SilentlyContinue | Select-Object -ExpandProperty ProviderOrder | Select-Object -First 1 | ForEach-Object {$_ -split ','}

            try {
                $NetworkProviderShortNames = $HWOrder
                $NetworkProviderShortNames += $Order | Where-Object {$NetworkProviderShortNames -notcontains $_}
                $NetworkProviderShortNames += Get-ChildItem -Path Registry::"HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\*\NetworkProvider" -ErrorAction SilentlyContinue | Get-ItemProperty | Select-Object -ExpandProperty PSParentPath | ForEach-Object { Get-Item -Path $_ | Select-Object -ExpandProperty PSChildName } | Where-Object {$NetworkProviderShortNames -notcontains $_}

                foreach ($NetworkProviderShortName In $NetworkProviderShortNames) {
                    $Properties = @{
                        ShortName = $NetworkProviderShortName
                        Name = $null
                        ProviderPath = $null
                        HWOrder = $null
                        Order = $null
                    }
                    $NetworkProvider = Get-ItemProperty -Path Registry::"HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\$($Properties.ShortName)\NetworkProvider" -ErrorAction SilentlyContinue
                    $Properties.Name = $NetworkProvider | Select-Object -ExpandProperty Name
                    $Properties.ProviderPath = $NetworkProvider | Select-Object -ExpandProperty ProviderPath
                    $Properties.HWOrder = ($HWOrder| ForEach-Object {$_.ToLower()}).IndexOf($Properties.ShortName.ToLower())
                    $Properties.Order = ($Order| ForEach-Object {$_.ToLower()}).IndexOf($Properties.ShortName.ToLower())
                    
                    $obj = New-Object -TypeName psobject -Property $Properties
                    Write-Output -InputObject $obj
                }
            }
            catch {
                Throw $_
            }
        }

        end {
        }
    }
#endregion Get-WindowsNetworkProvider
Get-WindowsNetworkProvider | Sort-Object -Property Order