VMware Cloud Community
muali
Contributor
Contributor
Jump to solution

Deploying VMs from CSV - Static IP assignment issue

Hello,

This is my first post and hoping if someone can assist/point me in the right direction with the following issue.

I’m using a script to deploy multiple VMs with static IP from a csv file.

Customization Spec is configured to prompt a user for IP.

The problem is everything goes as planned except the first VM skips the assigned IP and the next VM picks up the IP assigned for the first VM and the process goes on.

Example:

TestVM1 – 10.10.0.1

TestVM2 – 10.10.0.2

TestVM3 – 10.10.0.3

When the VM gets deployed, it provisions the VM as:

TestVM1 – DHCP assigned IP address

TestVM2 – 10.10.0.1

TestVM3 – 10.10.0.2

Script that I am using:

# List to deploy from CSV file with headings for script to pull from

$deploylist = " c:\VMdeploy.csv"

# vCenter name, use FQDN

$vcserver = " vCENTER01.domain.name"

# Connect to vCenter server.

Connect-VIServer $vcserver

# Deployment loop and customization done during server creation

Import-Csv $deploylist -UseCulture | %{

# Creates a New VM from the template

new-vm -Name $_."ServerName" -Template $_."Template" -Host $_."EsxHost" `

-Datastore $_."Datastore" -OSCustomizationSpec $_."Customization"

# Gets Customization info to set NIC and assign static IP address

Get-OSCustomizationSpec $_."Customization" | Get-OSCustomizationNicMapping | `

# Sets the Static IP info

Set-OSCustomizationNicMapping -IpMode UseStaticIP -IpAddress $_."IPAddress" `

-SubnetMask 255.255.255.0 -DefaultGateway $_."Gateway" -Dns $_."FirstDNS",$_."SecondDNS" `

# Set the Network Name

Get-VM -Name $_."ServerName" | Get-NetworkAdapter | Set-NetworkAdapter -NetworkName "Guest Network" -Confirm:$false

}

CSV file format:

ServerName

EsxHost

Datastore

Template

Customization

IPAddress

Gateway

FirstDNS

SecondDNS

Any assistance that I can get would be much appreciated.

Thank you

1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Why are you doing the Set-OSCustomizationNicMapping after the New-VM?

I would suspect that to come before the New-VM.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

2 Replies
LucD
Leadership
Leadership
Jump to solution

Why are you doing the Set-OSCustomizationNicMapping after the New-VM?

I would suspect that to come before the New-VM.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

muali
Contributor
Contributor
Jump to solution

That did it, can't believe it was that simple of a fix. Thank you so much.

0 Kudos