Jun 17
Virtual Machine Creation using Shell Script - vSphere 4
I’ve been asked recently by forumer in VMware Communities, “How can we create a Virtual Machine(VM) from ESX Service Console(SC) or Can’t we?“. When I looked back since the first day I’ve started working with ESX, not a single time I’ve created new VM through SC. I’ve agreed, we can do a lot of things via CLi such as :
- vmware-cmd –> Manage VM, start, stop, snapshot, register/unregister, connect devices & etc
- vmkfstools –> Create, clone, resize, convert VM virtual disk & etc
But that’s all! What about completely build new VM from SC like the one we did from vi-client?. Unless I missed out something, the answer is “NO” and seem imposible to me. Nevertheless, I’m writing this to show you how can we create the new VM using script that I build from scratch.

Note : I’m not very good in Shell script but this wasn’t going prevented me from achieving this objective.
So, what’s make this script?. I’ve started by assembling few useful commands as below :
- $echo –> will create all VM parameter to .vmx
- $mkdir –> will be used to create VM folder to Datastore
- $vmkfstools -> will be used to create VM disk
- $vmware-cmd –> will be used to register VM
Once I knew which commands need to be used and called first, I finally managed to produce below script “vmcreate.sh” within few minutes.
So, how the above script works?. At first, the script will require user input akin to what we have in vi-client. Second, it will print out all user inputs as a summary and wait for customer confirmation before proceed to the next step. Once confirmed, the script will start creating VM folder in the datastore based on given user input during the first step. Next, it will proceed to create virtual disk inside the VM folder. Then, VM configuration file (.vmx) will be created in the same folder before the script register the VM to the local ESX host as shown below.
Finally, I verified VM setting and it’s look everything was configured as expected.
Conclusion :
Yes, it’s possible for us to create new VM from SC using any script. Of-course, we actually no need to rely on real time user input instead we can build and run the script with all VM parameters included just in one line. Unfortunately as I’ve mentioned before, I’m not very good in scripting and I knew someone out there can build better script than mine.
ariyossss
athlon_crazy 17/06/2010 21:20PM
6 Comments so far
Leave a comment

[…] See original here: No-x Linux » Virtual Machine Creation using Shell Script – vSphere 4 Posted in: How To’s ADD COMMENTS […]
Although there are some nice scripts that you can use, not bad for this one.
Nice i wrote a Script (not really script 500 Rows LOL)
it does help you to Choose the Best Available ESX to Deploy on and also i Want to Save Always 10% on each VMFS so also it gives you to choose only the VMFS Luns that are going to stay above the 10% after you added the Wanted Storage.it does also Choses the Name of the VM by the Convension we use in the Organization with comparing to the Active Directory , It does lots of other stuff like with template and so on , so at the end , all the VM enviorment is Stable .
Hi Tal,
Wow! with 500 Rows I can’t imagine how long I need to spend my time before I can build such a huge script. BTW, your script will deploy VM to the best available ESX based on what?
Hi,
Could you please send me the script, so I can use it in my environment.
TSM, I’ve sent it but please remember that the script only been tested on ESX 4.