Recently i was working on project where i had to deploy RP4VM OVA on more than 400 ESXi hosts. So i decided to write article for OVA deployment via PowerCLI
Initially i faced a lot of issue like Deployment was stuck during ‘validation’, i couldn’t run simultaneous deployment in vcenter because of existing vcenter issue etc.
We used naming convention like VxRAIL(DC name)_vRPA1. You can change it if required.
We had to create VMKernel port on esxi hosts for other use, this is also included in last section of the script.
Here is the powercli code which i wrote, explained line by line
1 – It will load all PowerCLI module if you want to run script from PowerShell
3- Enter the vCenter name and username, password
5 – Please mention path to ova
7 – Please mention cluster name where you want to deploy OVA
11 – 19 – We used naming convention e.g . VxRail(Clustername)_vRPA1.
You can change as per your need.
23-26 – IP Settings for VMKernel port on ESXi hosts
29-51 – IP setting for OVA
54-81 – Loop for OVA deployment on ESXi host in cluster
85-99 – Port group and switch info for VMkernel assignment on ESXi.
Newer version of script available here
& 'C:\Program Files (x86)\VMware\Infrastructure\PowerCLI\Scripts\Initialize-PowerCLIEnvironment.ps1' Connect-VIServer vcenter -User username -Password password $filername = "path to OVA" $storenumber = 'number / name' ##################################################### $VMNAME = @() $vm = "VxRail$($storenumber)_vRPA1" $vm1 = "VxRail$($storenumber)_vRPA2" $VMNAME += $vm $VMNAME += $vm1 $i = 0 ######################################################3 $subnet = 'subnet' $subnetprefix = 'x.x.x' $ipperserver = 1 $firstip = 40 ################################################# ## collect IP information ######### $IPS = @() $vxrailip = Get-Cluster $storenumber | Get-VM | where {$_.name -like "VxRail*"} | Select Name, @{N="IPAddress";E={@($_.guest.IPAddress[0])}} $split = $vxrailip.IPAddress $IPbyte = $split.Split(".") $newucsip = ($IPByte[0]+"."+$IPByte[1]+"."+$IPByte[2]) $startip = "111" $endip = "112" $gateway = "126" $netmask = "subnet" $ucsipaddress = "$newucsip.$($startip+$_)" $ucsipaddress1 = "$newucsip.$($endip+$_)" $ucsgateway = "$newucsip.$($gateway+$_)" $IPS += $ucsipaddress $IPS += $ucsipaddress1 $internet = 0 ###########################################################3 foreach ($esxhost in (Get-cluster $storenumber | Get-VMHost | sort Name )) { $portgoup = $esxhost | Get-VirtualPortGroup |where {$_.name -like "Management*"} $datastore = $esxhost | get-datastore | where {$_.name -like "VxRail*"} ########################################### $virtual = $VMNAME[$i] $i ++ $protocol = $IPS[$internet] $internet ++ ##################################################### $ovfconfig = Get-OvfConfiguration -Ovf $filername $ovfconfig.Common.ip.Value = $protocol $ovfconfig.Common.netmask.Value = $netmask $ovfconfig.Common.gateway.Value = $ucsgateway $ovfconfig.DeploymentOption.Value = 'Med' $ovfconfig.IpAssignment.IpProtocol.Value = 'IPv4' $ovfconfig.NetworkMapping.RecoverPoint_Management_Network.Value = $portgoup ################################################# $esxhost | Import-VApp -Source $filername -datastore $datastore -OvfConfiguration $ovfconfig -Name $virtual -DiskStorageFormat Thin -Force | Start-VM -ErrorAction SilentlyContinue ########################################################### $vswitch = Get-VMHost $esxhost | Get-VDSwitch $pg = Get-VDswitch -VMHost $esxhost | get-VirtualPortGroup | where {$_.name -like "vSphere*"} ############################################################### 0..$($ipperserver-1) | %{ $ipaddress = "$subnetprefix.$($firstip + $_)" $firstip += $ipperserver New-VMHostNetworkAdapter -VMHost $esxhost -VirtualSwitch $vswitch -IP $ipaddress -SubnetMask $subnet -PortGroup $pg -ErrorAction SilentlyContinue } } New-DrsRule -KeepTogether:$false -Name vRPAAntiafffinity -Enabled:$true -Cluster $storenumber -VM VxRail$($storenumber)* -Confirm:$false -ErrorAction SilentlyContinue
Hope this helps… feel free to comment !!
2 comments
Comments are closed.