Hi Guys,
I am totally novice to scripting.
i have seen the script invoke-vmscript to change the IP address of the VMs. on the below website.
http://www.virtu-al.net/2010/02/05/powercli-changing-a-vm-ip-address-with-invoke-vmscript/
how can i adjust this script to read all ip addresses from a csv file or text file and apply them to multiple virtual machines.
Thanks in advance.
kgottleib
Great info. Thanks.
My VCenter is actually not on the same network as the VMs and can't communicate with them across the network. Apparently, I'm gonna have to disable UAC on the VMs via a domain GPO prior to changing the NICs. After disabling UAC and rebootign the VM the below command worked fine. After a bit of testing a treaking I came up with this.
get-vmguestnetworkinterface -vm $vmname -guestcredential $cred | where{$_.ip -ne $null} | set-vmguestnetworkinterface -ip "IP_Address" -netmask "255.255.255.0" -gateway "GW_Address" -dns "Primary_DNS","Secondary_DNS" -guestcredential $cred
The where{$_.ip -ne $null} command basically looks for a NIC with an IP assigned or an IP field that isn't empty. This would included either a currently configured static IP or an autoconfigured "dhcp" IP.
Now I just need to put it all together.
Shutdown VM = get-vm $vmname | shutdown-vmguest -confirm:$false
Reconfigure NIC = get-vm $vmname | get-networkadapter | set-networkadapter -type "vmxnet3"
PowerOn VM = get-vm $vmname | start-vm
Reconfigure IP info = get-vmguestnetworkinterface -vm $vmname -guestcredential $cred | where{$_.ip -ne $null} | set-vmguestnetworkinterface -ip "IP_Address" -netmask "255.255.255.0" -gateway "GW_Address" -dns "Primary_DNS","Secondary_DNS" -guestcredential $cred
It doesn't matter that vcenter is not on the same network. The invoke vmscript CMDlet that I use talk through VMware tools of the VM even when it's off the wire. That is it's specific function, To inject scripts inside the guest OS Through the VMware API.
After you swap out the adapter for the VMXnet3 VM willpower up without any IP address and the VM will not be on the network.