Some Useful PowerCLI scripts for VVD DIY-deployments

This blog contains some useful PowerCLI script which make the deployment of a VVD (4.3) a lot easier. It’s not a complete deployment script, some adjustments are needed.

for step Configure the Management Cluster in Region A

$location = Get-Folder -NoRecursion
$regionname = "nl01"
$dc = New-Datacenter -name $regionname"-m01dc" -Location $location
$cluster = New-Cluster -Name $regionname"-m01-mgmt" -DrsEnabled -EVCMode "intel-skylake" -Location $dc

for step Set SDDC Deployment Details on the Management vCenter Server in Region A

New-AdvancedSetting -Entity $global:DefaultVIServer -Name "config.SDDC.Deployed.Type" -Value "VVD" -Confirm:$false
New-AdvancedSetting -Entity $global:DefaultVIServer -Name "config.SDDC.Deployed.Flavor" -Value "Standard" -Confirm:$false
New-AdvancedSetting -Entity $global:DefaultVIServer -Name "config.SDDC.Deployed.Version" -Value "4.3.0" -Confirm:$false
New-AdvancedSetting -Entity $global:DefaultVIServer -Name "config.SDDC.Deployed.WorkloadDomain" -Value "Management" -Confirm:$false
New-AdvancedSetting -Entity $global:DefaultVIServer -Name "config.SDDC.Deployed.Method" -Value "DIY" -Confirm:$false
New-AdvancedSetting -Entity $global:DefaultVIServer -Name "config.SDDC.Deployed. InstanceId" -Value (new-guid) -Confirm:$false

for step Create a vSphere Distributed Switch for the Management Cluster in Region A

$regionname = "nl01"
$vdport = @()

#create DVS
$dvs = new-VDSwitch -name $regionname"-m01-vds01" -Mtu 9000 -NumUplinkPorts 2 -Location (get-datacenter)

#create DVS-ports
$vdport += $dvs | New-VDPortgroup -Name "$($dvs.name)-management" -VlanId 1611 -PortBinding Ephemeral
$vdport += $dvs | New-VDPortgroup -Name "$($dvs.name)-vmotion" -VlanId 1612 -PortBinding Static
$vdport += $dvs | New-VDPortgroup -Name "$($dvs.name)-vsan" -VlanId 1613 -PortBinding Static
$vdport += $dvs | New-VDPortgroup -Name "$($dvs.name)-nfs" -VlanId 1614 -PortBinding Static
$vdport += $dvs | New-VDPortgroup -Name "$($dvs.name)-replication" -VlanId 1612 -PortBinding Static
$uplink1port = $dvs | New-VDPortgroup -Name "$($dvs.name)-uplink01" -VlanId 2711 -PortBinding Static
$uplink2port = $dvs | New-VDPortgroup -Name "$($dvs.name)-uplink02" -VlanId 2712 -PortBinding Static

#set DVS-ports Load Balancing and teaming policies
$vdport | Get-VDUplinkTeamingPolicy | Set-VDUplinkTeamingPolicy -LoadBalancingPolicy LoadBalanceLoadBased
$uplink1port | Get-VDUplinkTeamingPolicy | Set-VDUplinkTeamingPolicy  -ActiveUplinkPort "dvUplink1" -UnusedUplinkPort "dvUplink2"
$uplink2port | Get-VDUplinkTeamingPolicy | Set-VDUplinkTeamingPolicy  -ActiveUplinkPort "dvUplink2" -UnusedUplinkPort "dvUplink1"

#upgrade to NIOC v3
$dvs = get-vdswitch $dvs
$DVSConfigSpec = New-Object vmware.vim.DVSConfigSpec
$DVSConfigSpec.networkResourceControlVersion = 'version3'
$DVSConfigSpec.ConfigVersion = $dvs.ExtensionData.Config.ConfigVersion
$dvs.ExtensionData.ReconfigureDvs($DVSConfigSpec)

#enable NIOC on DVS
$dvs.ExtensionData.EnableNetworkResourceManagement($true)

#set correct share on system Traffic types
$dvs = get-vdswitch $dvs
$DVSConfigSpec = New-Object vmware.vim.DVSConfigSpec
$DVSConfigSpec.ConfigVersion = $dvs.ExtensionData.Config.ConfigVersion
$DVSConfigSpec.InfrastructureTrafficResourceConfig = $dvs.ExtensionData.Config.InfrastructureTrafficResourceConfig
($DVSConfigSpec.InfrastructureTrafficResourceConfig | where-object {$_.key -match "faulttolerance"}).AllocationInfo.Shares.Level = "low"
($DVSConfigSpec.InfrastructureTrafficResourceConfig | where-object {$_.key -match "management"}).AllocationInfo.Shares.Level = "normal"
($DVSConfigSpec.InfrastructureTrafficResourceConfig | where-object {$_.key -match "nfs"}).AllocationInfo.Shares.Level = "low"
($DVSConfigSpec.InfrastructureTrafficResourceConfig | where-object {$_.key -match "virtualMachine"}).AllocationInfo.Shares.Level = "high"
($DVSConfigSpec.InfrastructureTrafficResourceConfig | where-object {$_.key -match "iSCSI"}).AllocationInfo.Shares.Level = "low"
($DVSConfigSpec.InfrastructureTrafficResourceConfig | where-object {$_.key -match "vmotion"}).AllocationInfo.Shares.Level = "low"
($DVSConfigSpec.InfrastructureTrafficResourceConfig | where-object {$_.key -match "vsan"}).AllocationInfo.Shares.Level = "high"
($DVSConfigSpec.InfrastructureTrafficResourceConfig | where-object {$_.key -match "vdp"}).AllocationInfo.Shares.Level = "low"
($DVSConfigSpec.InfrastructureTrafficResourceConfig | where-object {$_.key -match "hbr"}).AllocationInfo.Shares.Level = "low"
$dvs.ExtensionData.ReconfigureDvs($DVSConfigSpec)

It creates the DVS including the DVS-ports and it configures NIOC v3, you still need to add the hosts and migrate the vmkernel adapters.

For step Change Advanced Options on the ESXi Hosts in the Management Cluster in Region A:

Set-VMHostAdvancedConfiguration -VMHost (get-vmhost) -Name Config.HostAgent.plugins.hostsvc.esxAdminsGroup -Value "SDDC.Admins"
Set-VMHostAdvancedConfiguration -VMHost (get-vmhost) -Name VSAN.SwapThickProvisionDisabled -Value 1
Set-VMHostAdvancedConfiguration -VMHost (get-vmhost) -Name UserVars.SuppressShellWarning -Value 1

For step Create the VM and Template Folders in Region A

$regionname = "nl01"
new-folder $regionname"-m01fd-mgmt" -Location VM
new-folder $regionname"-m01fd-vra" -Location VM
new-folder $regionname"-m01fd-vraias" -Location VM
new-folder $regionname"-m01fd-vrops" -Location VM
new-folder $regionname"-m01fd-vropsrc" -Location VM
new-folder $regionname"-m01fd-vrli" -Location VM
new-folder $regionname"-m01fd-nsx" -Location VM
new-folder $regionname"-m01fd-bcdr" -Location VM

And after moving the vCenters to the mgmt-folder, remove the “Discovered virtual machine folder” with the following command

get-folder "Discovered virtual machine" | Remove-Folder -Confirm:$false

For step Create Anti-Affinity Rules for the Platform Services Controllers in Region A

New-DrsRule -Name "anti-affinity-rule-psc" -Cluster (get-cluster) -KeepTogether $false -VM (get-vm -name *psc*)

for step Set SDDC Deployment Details on the Compute vCenter Server in in Region A

New-AdvancedSetting -Entity $global:DefaultVIServer -Name "config.SDDC.Deployed.Type" -Value "VVD" -Confirm:$false
New-AdvancedSetting -Entity $global:DefaultVIServer -Name "config.SDDC.Deployed.Flavor" -Value "Standard" -Confirm:$false
New-AdvancedSetting -Entity $global:DefaultVIServer -Name "config.SDDC.Deployed.Version" -Value "4.3.0" -Confirm:$false
New-AdvancedSetting -Entity $global:DefaultVIServer -Name "config.SDDC.Deployed.WorkloadDomain" -Value "SharedEdgeAndCompute" -Confirm:$false
New-AdvancedSetting -Entity $global:DefaultVIServer -Name "config.SDDC.Deployed.Method" -Value "DIY" -Confirm:$false
New-AdvancedSetting -Entity $global:DefaultVIServer -Name "config.SDDC.Deployed. InstanceId" -Value (new-guid) -Confirm:$false

for step Configure the Shared Edge and Compute Cluster in Region A

$location = Get-Folder -NoRecursion
$regionname = "nl01"
$dc = New-Datacenter -name $regionname"-w01dc" -Location $location
$compcluster = New-Cluster -Name $regionname"-w01-comp" -DrsEnabled -EVCMode "intel-skylake" -Location $dc

add vm-hosts to the cluster and use the following script to create the resource pools.

New-ResourcePool -Name $regionname"-w01rp-sddc-edge" -Location $cluster -CpuSharesLevel High -CpuReservationMhz 0 -MemReservationGB 16
New-ResourcePool -Name $regionname"-w01rp-user-edge" -Location $cluster -CpuSharesLevel Normal -CpuReservationMhz 0 -MemReservationGB 0
New-ResourcePool -Name $regionname"-w01rp-user-vm" -Location $cluster -CpuSharesLevel Normal -CpuReservationMhz 0 -MemReservationGB 0

for step Configure vSphere DRS Anti-Affinity Rules for vRealize Operations Manager in Region A

$regionname = "nl01"
New-DrsRule -Name "anti-affinity-rule-vropsm" -Cluster (Get-cluster) -KeepTogether $false -VM (get-vm -name "vrop"$regionname"svr01*")
New-DrsRule -Name "anti-affinity-rule-vropsr" -Cluster (Get-cluster) -KeepTogether $false -VM (get-vm -name $regionname"vropsc01*")

for step Define a User Role in vSphere for vCenter Adapters in vRealize Operations Manager in Region A

New-VIRole -Name "vSphere Actions User" -Privilege (Get-VIPrivilege -Id VirtualMachine.Interact.PowerOn,VirtualMachine.Interact.PowerOff,VirtualMachine.Config.CPUCount,VirtualMachine.Config.Memory,VirtualMachine.Config.Resource,VirtualMachine.State.CreateSnapshot,VirtualMachine.State.RemoveSnapshot)

for step Define a User Role in vSphere for Storage Devices Adapters in vRealize Operations Manager in Region A

New-VIRole -Name "MPSD Metrics User" -privilege (Get-VIPrivilege -Id Host.CIM.CIMinteraction,Host.Config.Storage,StorageProfile.View,Storageviews.View)

for step Configure User Privileges in vSphere for Integration with vRealize Log Insight in Region A

New-VIRole -Name "vRealize Log Insight User" -privilege (Get-VIPrivilege -Id system.anonymous, system.view,system.read, host.config.advancedconfig, host.config.settings,host.config.network,host.config.netservice)

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to top