Powershell Logic and WMI NIC related stuff.

by Jul 9, 2015

Hi All,

This is my first post here and I am a complete Noob when it comes to PowerShell, so please be gentle :). Basically this week I've decided while things are quiet at work I'd start trying to teach myself some PowerShell. I'm an old hat at .cmd scripting but never really got into VB or VBS. Anyway I've done some googling and found some good beginnings from an MVP in the UK, but I'm just not sure how to extend on the logic that I found there to get what I want.

I'm looking at running some scripts on 2K8 servers so no PowerShell 3, only 2. What I want the scripts to do is configure some NIC settings, to start off with I need to identify the correct NICs and as I'm doing this on 2K8 servers I need to mess about with WMI. Here's what I've got so far:
—- cut —–

$strComputer = "."
$colItems1 = Get-WmiObject -class "Win32_NetworkAdapter" -computername $strComputer `
| Where {$_.MACAddress -ne $null -and $_.NetEnabled -eq "True" -and `
$_.NetConnectionID -eq "Local Area Connection"}
$colItems1 | fl *
$colItems1 | fl * | % {$_} | Out-File “C:TEMPLAN.txt

$colItems2 = Get-WmiObject -Class "Win32_NetworkAdapterConfiguration" -computername $strComputer `
| Where {$_.MACAddress -eq $colItems1.MACAddress}
$colItems2 | fl *
$colItems2 | fl * | % {$_} | Out-File “C:TEMPLAN2.txt

—- end cut —–
So at the moment what this gives me is 2 text files that show me two different sets of data for the SAME NIC. This is good and what I was expecting.

But if I drop the " -and $_.NetConnectionID -eq "Local Area Connection" and run it I get nothing in the second txt file.

What I want is to find all the active NICs on a machine using the first long line and then for every NIC that it finds, (There should be at least 3 if I drop the Local Area Connection bit), list out the settings in the "Win32_NetworkAdapterConfiguration" class. Once I get this loop right then I can work on actually configuring some settings.