Udostępnij za pośrednictwem


Windows Server 2012 - Get Binding Order For NICS in Powershell

I had a requirement the other day to retrieve the binding order for nics across several hosts in Windows Server 2012 but none of the scripts I found online worked!

Here is the code I came up with and ran against 16 hosts .

 

Only real pre-req is the WINRM / Remote Powershell is enabled for a host

 

here is the code!

<#
 
 .SYNOPSIS
 Retrieves the NIC Bindings for a Server 2012 Host (local or remote)
 
 .DESCRIPTION

 This script retrieves NIC's which are TCPIP Bound and outputs a text file per server detailing the bindings
 Input.txt is a text file with a server name per line
 .PARAMETER Serverlist

 .EXAMPLE
 
 .\GetBindings.ps1 -serverlist input.txt  
 
 #>

[CmdletBinding()]
#Validating the file exists before continuing into script
param([ValidateScript({test-path $_})][string]$ServerList)

function getbindings
{
 $bindings = (get-itemproperty "HKLM:\SYSTEM\CurrentControlSet\Services\Tcpip\Linkage").bind
 $returnobj = new-object PSobject
 [array]$bindingorder = $null
 foreach ($bind in $bindings)
 {
  $deviceid = $bind.split("\")[2]
  $adapter = (get-netadapter |where {$_.DeviceID -eq $deviceid}).Name
  $bindingorder += $adapter
 }

  $bindingorder
}

$servers = get-content $serverlist

$outputdir = $env:userprofile + "\Desktop\NICBindings"

$outputexist = test-path $outputdir

if ($outputexist -eq $false)

{

   new-item -type directory -path $outputdir

}

foreach ($srv in $servers)
{
 $results = invoke-command -computername $srv -scriptblock ${function:getbindings}

 $file = $outputdir + "\" + $srv + "_NICBindings.txt"
 $results |out-file $file
}

Comments

  • Anonymous
    April 05, 2014
    Thanks John. I didn't even know I needed this until I came across it looking for something else. I added it my server provisioning script (the beast). I appreciate you pointing this out. NIC bindings are important and I now use part of your function to ensure they are set properly.
  • Anonymous
    June 06, 2014
    Great! Thanks!