0

So I have been bashing my head on the KB trying to see whats best.

Using MDT / WDS to setup several BareBone machines that i have a list of, the hostnames, ip's and mac address. I can add this to a txt file, read the MAC address to the only connected NIC - compare it to the list in the txt file and then grab the variables to apply the correct hostname , IP's etc. MDT does not really have any Dynamic setting when applying hostname's and Nics. Anyone have a work around?

Sorta where i am

$CSV = import-csv "c:\Scripts\IPInfo.txt"

Foreach ($Item in $CSV)
{
$MAC = $Item.MacAddress

$MAC_CMD = (Get-WmiObject win32_networkadapterconfiguration -ComputerName $env:COMPUTERNAME | Where Macaddress -eq $MAC | Select-Object -Expand macaddress) -join ","

$MAC_Dash = $MAC_CMD -replace ":", "-"
#Write-host $MAC_DASH

$ActiveNic =  Get-NetAdapter | where MacAddress -EQ $MAC_Dash | select -ExpandProperty name
#Write-Host "$ActiveNic"

#Write-Host "(in the loop) ip: $Computer"

if ($MAC_CMD -eq $Item.MacAddress){
$Computer = $Item.ComputerName
$IPaddress = $Item.IPAddress
$Subnet = $Item.SubnetMask
$GateWay = $Item.Gateway
$DNS1 = $Item.Dns1
$DNS2 = $Item.Dns2
}

}

Write-Host $ActiveNic

so far the txt has the following

computerName,IPAddress,SubnetMask,Gateway,Dns1,Dns2
devops-bg,10.1.0.57,255.255.255.0,10.1.0.1,10.1.0.18,10.1.0.13,

in theory, id like to grab the mac address of the "Active " nic and then compare that to the txt file

Luis
  • 83
  • 2
  • 10
  • 1
    If by "work around" you mean "can someone write this code for me," then the answer is generally "no," because this is a programmer's Q&A site. You need to put the code you are using into your question and explain specifically _how_ it doesn't work. – Bill_Stewart Dec 05 '17 at 21:09
  • 1
    Questions about those tools are best asked on superuser and/or serverfault. (This is a programmer's Q&A site.) – Bill_Stewart Dec 05 '17 at 21:20
  • What do you mean by "grab the MAC address of the 'active' NIC and then compare that to the text file"? – Bill_Stewart Dec 05 '17 at 21:36
  • If you are going to use Powershell then remove the batch-file tag from your question. – Squashman Dec 05 '17 at 21:37
  • So you need to `Set-NetIPInterface -InterfaceAlias "Ethernet" -DHCP Disabled` before you attempt to run `Set-NetIPAddress`? – TheMadTechnician Dec 06 '17 at 22:57
  • @TheMadTechnician I re-wrote my script bc there are several nics all active and need to match the one in the csv file. i edited the above code BUT i cant get the $ActiveNic variable outside the loop. its not in "scope" ? read up on it but not sure how to extract the variable outside the loop – Luis Dec 07 '17 at 21:46
  • WOW all i had to do was add a += to the command!? Also needed to do $ActiveNic = @() – Luis Dec 07 '17 at 22:09

0 Answers0