PowerCLI: Changing a VM IP Address with Invoke-VMScript
Alan Renouf is a community peer for VMware PowerCLI, Virtu-Al.Net. In 2009, he was named a vEXPERT by VMware. Alan's main focus is to teach and help other VMware admins automate their VMware infrastructures and make their lives easier through automation.
www.virtu-al.net.
One of the cmdlets that has been much improved in the recent version of PowerCLU 4 U1 is the Invoke-VMScript cmdlet,
This cmdlet runs a script or command inside the guest OS of each of the specified virtual machines. To run Invoke-VMScript, the user must have read access to the folder containing the virtual machine and a Virtual Machine.Interaction.Console Interaction privilege.
The virtual machines must be powered on and have PowerShell and VMware Tools installed.
Network connectivity to the ESX system hosting the virtual machine on port 902 must be present.
You must also have both the Host and guest credentials available.
One question asked of me recently was “Is there a way to set the IP address of some windows virtual machines with PowerCI ?”.
So with the power of the invoke-cmdlet in the following example you can see how you can change the ip address by using the netsh command inside the VM.
As a note, you no longer need PowerShell inside the guest OS for this cmdlet to work, as you can see below I am calling a batch command, you can also use this cmdlet against *nix machines to run shell commands.
This of course can easily be adjusted to read all ip addresses from a csv file or text file and apply them to multiple virtual machines if needed.
The script is as follows:
And to see it in action I shot a quick video of the script in action:
PowerCLI Invoke-VMScript cmdlet from Alan Renouf on Vimeo.
Further examples of this cmdlet can be found in Arnim’s great example here:
http://www.van-lieshout.com/2010/01/powercli-get-wmi-info-from-isolated-guests/
And Arne’s great script here:
http://ict-freak.nl/2010/01/20/update-linux-vms-with-powercli-thanks-to-invoke-vmscript/
- xtravirt's blog
- Login or register to post comments
Spotlight:
VMware Documentation Downloader v11.08.30
Updated for vSphere 5 - A free tool for those on the move who need information FAST
vSphere 5 License Entitlement Changes
See what has changed in the license entitlement in vSphere 5?
Thin Client vs Zero Client
The differences between Thin and Zero desktop clients for VDI

