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