VMware

This Question is Possibly Answered

1 "correct" answer available (10 pts) 2 "helpful" answers available (6 pts)
1 Replies Last post: Nov 3, 2009 7:26 AM by bulletprooffo…  

Script for creating VM's and powering on posted: Nov 3, 2009 7:03 AM

Click to view Guv's profile Enthusiast 70 posts since
Sep 5, 2008

I have written few commands below on setting up a new virtual machine on a specfic vmhost and then attaching iso image to the cd drive and then powering on VM. But I wanted to find out how I can combine all these commands into a function, then run the function by giving a parameter which is the virtual machine and also maybe the iso image.

The command for creating a VM on a specific host I used was :

get-vmhost 'VMhost' | new-vm -name 'name -datastore (get-datastore 'datastore) -diskmb ( 8GB / 1MB ) -memoryMB ( 1gb / 1mb )

get-vm 'name' | new-cddrive -isopath $isopath -startconnected

Start-VM 'name'

How can you combine the above in a script by applying parameters such as name and iso path (if that is possible).

Any advise, or is there is downloadable script for creating VM's

Re: Script for creating VM's and powering on

1. Nov 3, 2009 7:26 AM in response to: Guv
Click to view bulletprooffool's profile Master 806 posts since
Apr 14, 2009

You need something like (not tested . . done freehand as I don;'t have powershell on the machine):

$name = read-host "Please Specify VM Name"

$iso = Read-Host "Please specify ISO"

$datastore = Read-Host "Please specify Datastore"

Function BuildVm ($name, $isoimage, $Datastore)

{

get-vmhost 'VMhost' | new-vm -name $name -datastore (get-datastore $datastore) -diskmb ( 8GB / 1MB ) -memoryMB ( 1gb / 1mb )


get-vm $name | new-cddrive -isopath $iso -startconnected

Start-VM $name
}

BuildVM ($name, $iso, $Datastore)

VMware Developer

SDKs, APIs, Videos, Learn and much more in the Developer community.

Learn More

Developer Sample Code

Increase your developer productivity with VMware API sample code.

Learn More

VMworld Sessions & Labs

Online access to the latest VMworld Sessions & Labs and online services.

Learn more

Purchase PSO Credits Online

Purchase credits to redeem training and consulting services online.

Buy Now

Community Hardware Software

View reported configurations or report your own.

Learn More

VMware vSphere

Come witness the next giant leap in virtualization.

Register Today

Communities