VMware Cloud Community
sureshadmin2011
Enthusiast
Enthusiast
Jump to solution

Powecli set IP for a Windows virtual machine from IP pool

Hi,

I have followed every step from this article https://pubs.vmware.com/vsphere-55/index.jsp?topic=%2Fcom.vmware.vsphere.networking.doc%2FGUID-DBF79... and i need the below to get it working,

1. As per the article when a IP pool is configured, mapped to a portgroup, VM in that network is vApp options enabled and i set it to static IP pool.

2. So when a VM is powered on the network adapter of the Vm should be assigned a IP from the IP pool.

3. But VM NIC adapter never gets assigned with a IP from pool and VMware confirmed that IP pool do NOT have a ability to push a IP to the VM.

So i'm looking for a script which can be kept inside the VM and pull a IP address from the IP pool or vAPP option of the machines and assign the the VM(Windows) NIC adapter. Probably via the VMware tools? Please let me know any possibility for this?

0 Kudos
1 Solution

Accepted Solutions
Craig_Baltzer
Expert
Expert
Jump to solution

Using IP pools is like poking yourself in the eye; it feels better when you stop Smiley Happy

If you can't use DHCP and have to use IP pools then there is a ton of up front configuration mucking about to do:

  1. Follow the first article you linked
  2. In vApp options for the VM go under Properties and create a property for each of the things you want to get from the IP Pool (i.e. IP, etc.). When creating the entries under type pick  Dynamic property then find the correct entry in the drop-down list so the values come from the IP pool
  3. pastedImage_9.png
  4. Setup an auto-start task (Scheduled Task that starts on boot) in your template VM to run a script that:
    1. Waits for VMware tools to get started
    2. Runs vmtoolsd to get the values from the vApp into the VM in XML format
      1. "C:\Program Files\VMware\VMware Tools\vmtoolsd.exe" --cmd "info-get guestinfo.ovfEnv"
    3. Parse the XML file to extract the IP, etc.
    4. pastedImage_11.png
    5. Run the OS commands (netsh, wmic, vbScript (wmi) or Powershell (maybe native, maybe wmi depending on version)) to take the values from the XML file and set the OS options

Aside from all this configuration it scales poorly as the "Network" in the Dynamic property is tied to a specific port group. If you're trying to deploy this widely then it means one template VM per port group (blech!)

Hope this helps to get you started (or convinces you to use DHCP Smiley Happy)

View solution in original post

0 Kudos
8 Replies
sureshadmin2011
Enthusiast
Enthusiast
Jump to solution

There is a example here http://www.v-front.de/2014/01/building-self-configuring-nested-esxi.html which uses a python script to assign to nested ESXi created on the VM.

Need similar one for Windows VM to pull IP from IP pool and set to NIC adapter.

0 Kudos
Craig_Baltzer
Expert
Expert
Jump to solution

Using IP pools is like poking yourself in the eye; it feels better when you stop Smiley Happy

If you can't use DHCP and have to use IP pools then there is a ton of up front configuration mucking about to do:

  1. Follow the first article you linked
  2. In vApp options for the VM go under Properties and create a property for each of the things you want to get from the IP Pool (i.e. IP, etc.). When creating the entries under type pick  Dynamic property then find the correct entry in the drop-down list so the values come from the IP pool
  3. pastedImage_9.png
  4. Setup an auto-start task (Scheduled Task that starts on boot) in your template VM to run a script that:
    1. Waits for VMware tools to get started
    2. Runs vmtoolsd to get the values from the vApp into the VM in XML format
      1. "C:\Program Files\VMware\VMware Tools\vmtoolsd.exe" --cmd "info-get guestinfo.ovfEnv"
    3. Parse the XML file to extract the IP, etc.
    4. pastedImage_11.png
    5. Run the OS commands (netsh, wmic, vbScript (wmi) or Powershell (maybe native, maybe wmi depending on version)) to take the values from the XML file and set the OS options

Aside from all this configuration it scales poorly as the "Network" in the Dynamic property is tied to a specific port group. If you're trying to deploy this widely then it means one template VM per port group (blech!)

Hope this helps to get you started (or convinces you to use DHCP Smiley Happy)

0 Kudos
sureshadmin2011
Enthusiast
Enthusiast
Jump to solution

Yes you are correct, ip pools hurt badly Smiley Happy

You have nailed the 2 points which i was hunting for with clear screenshots, on how to add that dynamic property and on how to read ovf properties from inside the win guest machine.

Going to try this right away will post back if have any doubt or struck any where.


You are brilliant! this piece of info is not available with VMware support even believe me!

Thanks a Zillion for replying!!!

0 Kudos
sureshadmin2011
Enthusiast
Enthusiast
Jump to solution

I have tried this, but getting struck at dynamic properties.

In you "edit property settings" screen shot in the field "category" i see Network value. But in my environment (vsphere 5.5, vmversion 10) the list box is empty.

Also down below, in "Macro" field i get only one option "Vcenter server ip Address"

Can you please shed some light on this?

ippool.png

0 Kudos
Craig_Baltzer
Expert
Expert
Jump to solution

Category is something you type in; in my example I typed "Network" into the category box.

As for the missing dynamic properties, make sure the VM is connected to a port group that is linked to the IP Pool.

I don't have a 5.5 environment handy but this isn't new 6.0 only functionality so it should work...

0 Kudos
sureshadmin2011
Enthusiast
Enthusiast
Jump to solution

Thanks Craig.

VM is connected to a port group mapped to IP POOL but somehow the web client do not show dynamic properties.

But noticed in vSphere Windows client works perfect.

Already started working on a powershell script to extract IP details fetched from vmware tools. Currently deeply reading powershell regex Smiley Happy

Thanks a Ton!

0 Kudos
Craig_Baltzer
Expert
Expert
Jump to solution

Glad to hear you're rolling again. If you can share your script here when you get it working I'm sure folks would be interested in seeing it

0 Kudos
sureshadmin2011
Enthusiast
Enthusiast
Jump to solution

This is the code to fetch IP from XML and set to NIC,

I have vmtoolsd.exe in my windows environment path variable.

I have four dynamic properties defined IP, Mask, Gateway and DNS.

$command = @'

cmd.exe /C vmtoolsd.exe --cmd "info-get guestinfo.ovfEnv" > C:\temp\poolip.txt

'@

Invoke-Expression -Command:$command

$cont = @()

$cont = Get-Content c:\temp\poolip.txt

$regex = [regex] "\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}"

$ips = $regex.matches($cont)

$dns = $ips[0].value

$ipaddr = $ips[1].value

$mask = $ips[2].value

$gateway = $ips[3].value

Invoke-command{

netsh interface ip set address "Local Area Connection" static $ipaddr $mask $gateway

netsh interface ip add dns "Local Area Connection" $dns}

Thanks Again!

0 Kudos