Calling all ESX admins! I am looking for novel ideas for scripts to write for the upcoming VMware Toolkit for Windows PowerShell. Yes–I am offering to do the writing. I am doing research for a project (details of which to be announced in the coming weeks), and I could use some really great ideas of missing functionality or fixes to problems you have seen while working with VMware Virtual Infrastructure 3. Pointers to something cool you have seen done with the VMware Perl Toolkit are good too. It’ll be amusing to see how much simpler those will be in PowerShell.
So please share anything you can come up with. You can leave them in the comments or contact me directly. Thanks!

Got one from IRC:
Just thought of another one myself. I’d like to easily remove one or more virtual hardware devices (such as an unnecessary sound or USB controller) across multiple systems.
You could write one to add multiple port groups across many host servers. This is so nice when trunking many VLANs at once.
Thanks Andrew, I’ll add that to my list.
A way to create a snapshot that expires in a specified number of hours would be awesome.
Hi
I would love to have a list of all active snapshots, the time they are running (or creation date), comment and VM they belong to.
Gabrie
@Mark, cool idea, I’ll see if that’s doable. @Gabrie, try this:
$snap = get-vm | get-snapshot$snap | ft @{l = "VM"; e = {$_.vm.name} },name,created,description
From the VITK forum: “I want CPU Ready information, i.e. the amount of time a VM is READY to RUN but must WAIT for a the right number of cores to become available.”
It would be nice if esxcfg-mpath commands could be used.
You can edit the SAN multipath policy and other related stuff via the VI toolkit. I’ll have to write about that someday.
How about a config script that can be used after a host has been created (initial ESX installation) that copies all the network configuration info from an existing ESX host (i.e. vswitches, portgroups, service consoles, etc) to the new host(s). (autoincrement/user input IP addresses?) or if you have made an update on one host, the script can just update all other hosts.
make it so that it can copy to all new servers or just one. I started work on this a while ago but have not had time to finish it.
“I started work on this a while ago but have not had time to finish it.”
yeah, me too.
I’m pretty sure we’ll see a script to do this come out of the VI PowerShell contest (http://vmware.com/go/powershellcontest/).
Search the Inet for “configureESX.ps1″
Thats should do
But can configureesx.ps1 Read an existing esx host’s config, let you tweak, then redeploy that config to a fresh install?
How about a script that creates a new VM based on a template and the settings in the customization wizard?
Script? That’s a one-liner!
get-template MyTemplate | new-vm -vmhost esxserver01 -name MyVM -OSCustomizationSpec MySpec
How about changing the IP address during the cloning process?
What is the difference between a Template and a virtual machine?
Right now you actually can’t change the IP during a clone using the VI Toolkit. This is a big glaring hole unfortunately.
Template is a VM that is marked as a template. It’s identical underneath the covers. But you can do more stuff with a template with regards to VM deployment.
Yes, that is a bummer, when you have to deploy 30 VMs at a time with static IP addresses.
When I did try with a known good customization tempate and the following command line command line,
get-template w2k3stdR2-template | new-vm -vmhost mytestesx01.internal.dev.org -name ScriptVM01 -OSCustomizationSpec PCK_W2k3_32BIT_STD
the process runs to about 95% then fails with this error:
8/28/2008 3:48:01 PM New-VM BB572FA5-355A-4225-BBEF-8A035305A24E The operation for the entity vm-2663 failed with the following message: “Customization failed.”
At line 3, position 99
get-template w2k3stdR2-template | new-vm -vmhost mytestesx01.internal.dev.org -name ScriptVM01 -OSCustomizationSpec PCK_W2k3_32BIT_STD
Thoughts?
is it possible to create a script that will display list of available templates (all in “template” folder) and list of all clusters and a list of all datastore that are available to the chosen cluster – so that a remote admin can simply deploy a vm from a template he selected?
Most definitely.
# list all templates in a single folder
get-folder “Templates” | get-template
Datastores are not associated with clusters, they are attached to host servers, so we have to do this:
# list datastores avail to cluster member host server
(get-cluster “DRS cluster Foo” | get-vmhost)[0] | get-datastore
The (blah)[0] stuff grabs only the first host server in the cluster. You could pipe get-vmhost to get-datastore, but you’d get duplicate results.
There you go
$newtemp = New-VM -Name $template -VMHost $esxhost -Datastore $datastore -MemoryMB 4096 -NumCpu 2 -GuestId winLonghorn64Guest -cd -Description (Get-Date)
$newtemp|Get-CDDrive |Set-CDDrive -Connected $true -IsoPath $isopath -StartConnected $true -Confirm:$false |Out-Null
New-HardDisk -vm $newtemp -CapacityKB (60*1024*1024) -ThinProvisioned |Out-Null
New-HardDisk -vm $newtemp -CapacityKB (20*1024*1024) -ThinProvisioned |Out-Null
$vmview=$newtemp|get-view
$vmview.MarkAsTemplate()
A slight variation on the templating one.
I’d like to maintain a machine as a live template – sitting idle on my network , picking up security updates / build tweaks and AV data.
Untill “hot cloning to template” is available ( not gone to update 2 yet ) I’m looking for a script that I can run as a scheduled task to shut a specified guest down , and clone to a template ( overwriting the last template ), then boot it back up.
I’m a complete powershell virgin but have seen the light at a recent usergroup meeting
I like it. That would not be very hard to do, I think. Which user group meeting was this?
The London one – They mentioned the book – look forward to its release !
These posts have really got me interested in powershell.
Stumbled upon this site while looking for a template deploy method that uses the customization files. Winner ! Now added to my RSS.
I’ve also been searching around trying to find a script to export the memory overhead figures now displayed in the VI client out to CSV for our capacity management database.
I’ll stick a post in the communities, but given the knowledge here i thought i’d start here.
Any thoughts appreciated..
I hesitate to call it a script, it’s more of a two-liner, but here you go.
$MemOverheadCol = @{ Name = "MemoryOverhead"; Expr = { $_.Runtime.MemoryOverhead / 1MB } }Get-VM | Get-View | Select-Object Name, $MemOverheadCol | Export-Csv file.csv -noType
How about a script to deploy a thin vm from a template on an nfs datastore.
Looking for the ultimate documentation script to document everything under the sun in VI Datacenter if you can think of it, doc it.
A lot has happened since I made this first post. Check out this page for some awesome scripts, at least two of them dealing with documenting: http://www.vladan.fr/top-10-powershell-scripts-for-virtual-infrastructure/
It would be great if you could come up with a script to delete virtual machines and remove them from inventory. We schedule weekly cloning of our virtual servers to a backup ESX box, however, it will not overwrite existing clones. So, we have to manually delete them from the backup box every week before the scheduled cloning kicks in. I wrote a script to delete them from disk, but they still appear in the VC as “orphaned”, and you have to right click it and remove it from inventory.
It would be nice to create OS Customization Specs with static IP information in them. Currently, I don’t see any option to specify static IP config parameters (IP, NetMask, Gateway) in New-OSCustomizationSpec. Any thoughts?
I am looking at mounting a vmdisk and modifying some required to get the vm ready for deployment and later cloning the server, any help will be appreciated how I can copy the files after the cloning or before cloning
I’m going to go ahead and close comments on this post as the book is done and published. You can still reach out to me in other ways. For PowerCLI (the new name of the VI Toolkit) advice, your best best for a prompt answer is to visit the forums which can be found at http://vmware.com/go/powershell.