1

I want to get a "first logon" script going that will auto create VLANs and set static IP's based on a CSV file that contains all the IP addresses for every workstation in the company (after a re-image is complete).

I plan to start with looking into the suggestions we already have on a previous post here. However, the previous post is for a single adapter, and each of our systems consist of 5 different VLANs:

VLAN1
VLAN2
VLAN3
VLAN4
VLAN5

Also, my CSV will only need IP and Subnet mask. No need for gateway or DNS.

My question is, what would be the best way to structure the information in the CSV file to get this to work best? The CSV will need the info for the 5 seperate VLANs:

Example CSV:

computerName,AdapterName,IPAddress,SubnetMask,
TestMachine2,VLAN1,10.1.0.1,255.255.255.0,
TestMachine2,VLAN2,10.2.0.1,255.255.255.0,
TestMachine2,VLAN3,10.3.0.1,255.255.255.0,
TestMachine2,VLAN4,10.4.0.1,255.255.255.0,
TestMachine2,VLAN5,10.5.0.1,255.255.255.0,
TestMachine3,VLAN1,10.1.0.1,255.255.255.0,
TestMachine3,VLAN2,10.2.0.1,255.255.255.0,
TestMachine3,VLAN3,10.3.0.1,255.255.255.0,
TestMachine3,VLAN4,10.4.0.1,255.255.255.0,
TestMachine3,VLAN5,10.5.0.1,255.255.255.0,

Does the above look OK?

The current script is only the creation and renaming part of the VLAN Adapters, but it would be grand if anyone is able to help me build the remaining section which applies the IP Addresses based on the CSV file:

# Import Intel Commandlets
Import-Module -Name "C:\Program Files\Intel\Wired Networking\IntelNetCmdlets\IntelNetCmdlets"

# Create VLANs

$IntelNic=Get-IntelNetAdapter -Name "Intel(R) Ethernet Converged Network Adapter X550-T2"
$adapterVLANs=(
  @{"VLAN"="1"; "Name"="VLAN1"},
  @{"VLAN"="2"; "Name"="VLAN2"},
  @{"VLAN"="3"; "Name"="VLAN3"},
  @{"VLAN"="4"; "Name"="VLAN4"},
  @{"VLAN"="5"; "Name"="VLAN5"}

)
foreach($adapter in $adapterVLANs)
{
  Add-IntelNetVLAN -Parent $intelnic -VLANID $adapter["VLAN"]
  Set-IntelNetVLAN -Parent $intelnic -VLANID $adapter["VLAN"] -NewVLANName "$($adapter["VLAN"]) - $($adapter["Name"])"
}

Sleep -Seconds 10

# Rename Adapters

Rename-NetAdapter -Name "Ethernet 3" -NewName "MAIN"
Rename-NetAdapter -Name "Ethernet 5" -NewName "VLAN1"
Rename-NetAdapter -Name "Ethernet 6" -NewName "VLAN2"
Rename-NetAdapter -Name "Ethernet 7" -NewName "VLAN3"
Rename-NetAdapter -Name "Ethernet 8" -NewName "VLAN4"
Rename-NetAdapter -Name "Ethernet 9" -NewName "VLAN5"

# Rename Adapters

Next part goes here... set IP address for each VLAN based on what is read from the CSV file

Any help much appreciated. Thanks.

Mastaxx
  • 125
  • 6
  • What is your actual problem doing what you need to do? All you need to do is read the CSV and use e.g. Where-Object to find the Information for VLANX? – Seth Sep 23 '21 at 10:26
  • I need to set the IP address for each VLAN based on what it reads from the CSV file – Mastaxx Sep 23 '21 at 10:28
  • You already do have the other question linked that does set the IP. A slighty more modern approach would be to use [Set-NetIPAddress](https://learn.microsoft.com/en-us/powershell/module/nettcpip/set-netipaddress?view=windowsserver2019-ps). Setting IPs won't be any different and as mentioned finding the information from your CSV is using a Where-Object Statement or similar. Just iterate your CSV and grab the proper adapters. – Seth Sep 23 '21 at 10:40

0 Answers0