I need to write a Power Shell script that basically does the following:
1) Get details of vCenter/ESX from user
2) Display the data stores available and allow user to choose the data store on which he wants to create the virtual machines
3) Ask for no of VMs to be created
4) Create the designated no of VMs having the following specs
a. 3 virtual disks with option given to user for thin/thick provisioning
b. 3 virtual CD drives mapped to ISO files on a data store (which will be connected at startup)
c. 4 NIC cards
Any help would be highly appreciated
Regards
Dhiman
Give this a try.
Note that there are some open questions.
1) when the user selects to connect to the vCenter, which VMHost shall be used to create the guests ?
2) it's not clear how the ISO-path shall be obtained.
$connectName = Read-Host -Prompt "Provide the name of the vCenter or the ESX(i) host" Connect-VIServer -Server $connectName $ds = @(Get-Datastore) for($i=0; $i -lt $ds.Count; $i++){ Write-Host ($i+1),":",$ds[$i] } $dsNr = Read-Host -Prompt "Enter the number of the target datastore" $dsImpl = $ds[$dsNr-1] $nrVM = Read-Host -Prompt "Who many guest do you want to create ?" $hdFormat = Read-Host -Prompt "Should the guest have a thick or a thin virtual disk ?" if($hdFormat -eq 'thin'){$thinSwitch = $true}else{$thinSwitch = $false} 1..$nrVM | %{ $vm = New-VM -Name ("guest" + $_) -Datastore $dsImpl -DiskStorageFormat $hdFormat 0..1 | %{$vm | New-HardDisk -Datastore $dsImpl -ThinProvisioned:$thinSwitch -CapacityKB (4*1MB) -Confirm:$false} $netName = ($vm | Get-NetworkAdapter).NetworkName 0..2 | %{$vm | New-NetworkAdapter -NetworkName $netName -Confirm:$false} 0..2 | %{$vm | New-CDDrive -Confirm:$false } } Disconnect-VIServer -Confirm:$false
____________
Blog: LucD notes
Twitter: lucd22
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi Luc,
Thank you so much for your answer. Ill give it a try right away.
For selecting the VMHost, I will be giving an option by calling Get-VMHost and choosing the host.
I have solved the upload issue by using:
$vcServer = Connect-VIServer -Server: -Destination MyDS:\Folder2\ -Force
Thanks once again!!!
Regards,
Dhiman