Offline Install VMware Powercli and creating multiple VMs from template

 

1.Save the powercli modules to any machine that have internet access:

open powerchell:

Save-Module -Name VMware.PowerCLI -Path C:\Path\



2.Now copy the module folders to offline system:

 C:\Program Files\WindowsPowerShell\Modules


3.Save below content to createVM.ps1 file and run:



********************


# Specify vCenter Server, vCenter Server username and vCenter Server user password

$vCenter="192.16.1.1"

$vCenterUser="administrator@ranji.com"

$vCenterUserPassword="Password"

#

$ESXi="<ESXI IP>"

#$ds = Get-Datastore -Name 'PSG2_DS'

$cloneName = "<Existing VM template>"

# Specify the VM name to the left of the - sign

$VM_prefix = "<NewVMName->"

$vm_count = "10"

#

Set-PowerCLIConfiguration -InvalidCertificateAction Ignore

write-host "Connecting to vCenter Server $vCenter" -foreground green

Connect-viserver $vCenter -user $vCenterUser -password $vCenterUserPassword -WarningAction 0

1..$vm_count | foreach {

$y="{0:D1}" -f + $_

$VM_name= $VM_prefix + $y

$ds = Get-Datastore -Name 'My_DS'

write-host "Creation of VM $VM_name initiated"  -foreground green


$vm = New-VM -Name $VM_name -VM $cloneName -Datastore $ds -VMHost $ESXi

write-host "Power On of the  VM $VM_name initiated"  -foreground green

Start-VM -VM $VM_name -confirm:$false -RunAsync

}

No comments:

Post a Comment

How to increase ESXi webclient login user application timeout

 To increase the default 15min timeout to 2hr Login to the esxi webclient on the right top corner ->Click the User login tab Select "...