VMware HA Cluster: Set-Advanced HA Settings

Recently a adjustment was made to the vCenter Cluster HA Agent timeout Settings.

Ref: https://kb.vmware.com/s/article/2017778

Performing a Reconfigure for VMware HA operation on a primary node causes an unexpected virtual machine failover

This calles for at script, because there is no way we are going to do this by hand! Feel free to use or alter the script, just remember. It is all done at your own risk.

Continue reading VMware HA Cluster: Set-Advanced HA Settings

Control OpenSLP on ESXi hosts using PowerCLI

I light of recent security vulnerabilities found in the OpenSLP service on ESXi. A recommended workaround is to disable the OpenSLP service all together.

Vulnerability information: https://www.vmware.com/security/advisories/VMSA-2021-0002.html

Workaround KB: https://kb.vmware.com/s/article/82374

This powershell script will help you control the OpenSLP service.

Continue reading Control OpenSLP on ESXi hosts using PowerCLI

PowerCli Script: Migrate host from missing dvSwitch to new dvSwitch with same Id’s

The purpose of this script is to migrate from one vCenter to another when using dvSwitches. The dvSwitch is bound to vCenter, so in order to migrate hosts from one vCenter to another you can map the networks using this script. All you need to do is disconnect the host from the original vCenter with the VMs still running, but not remove it. Then you connect it to the new vCenter.

Continue reading PowerCli Script: Migrate host from missing dvSwitch to new dvSwitch with same Id’s

PowerCLI Script: Check if you have VMs with USB contollers

I light of many serious vulnerabilities in vSphere ESXi revolve around the USB controller, here is a script that will list the virtual machines that have an USB controller attached.

Requirements:

You need to have the VMware.PowerCLI module installed. This can be done with the commands:

Continue reading PowerCLI Script: Check if you have VMs with USB contollers

Migrate Tags from one vCenter to another

When upgrading to vSphere 7 or any other version, you might choose to create a brand new vCenter instead of migrating the old one. But what about folder structure, tags, distributed switches and so on.

Here I will demonstrate how you can easily migrate your tags from one vCenter to another using VMware PowerCLI.

Continue reading Migrate Tags from one vCenter to another

Powershell: Find largest VM disk

Sometimes you need to find the largest virtual disk. Lets say if you are sizing LUNs for datastores.

Here is a script that help you do that.

Requirement are powershell and the VMware.PowerCLI module.

Use it at your own risk.

Import-Module VMware.PowerCLI

Connect-VIServer <vCenter Name>


Function Get-LargestDisk {
  param(
    $Datastores=$null
  )
  $largest = 0

  if ($Datastores -eq $null) {
    Write-Host "Searching through all VMs."
    $vms = Get-VM
  } else {
    Write-Host "Searching through VMs on datastores: $Datastores"
    $vms = $Datastores | Get-VM
  }

  foreach ($vm in $vms) {
    $hdds = $vm | Get-HardDisk

    foreach ($hdd in $hdds) {
      $size = $hdd.CapacityGB

      if ($size -gt $largest) {
        Write-Host "Found a larger VM: $vm Size: $size GB"
        $largestVm = $vm
        $largest = [math]::Round($size)
      }
    }
  }
  Write-Host "Largest Disk: $largest GB Largest VM: $largestVm"
}

Get-LargestDisk -Datastore (Get-Datastore V7000*)

Powershell: Migrate Standard Portgroups

Hi, just wanted to share this piece of code with you. This short script creates a mirror of virtual portgroups from one vSphere ESXi host to another.

I only takes the name and vlan id into account, so all policies, nics and other settings are not migrated at this time, but it is easy to do. I however does not always want that.

You need VMware.PowerCLI module for it to work.

Use it at you own risk.

Import-Module VMware.PowerCLI

connect-viserver <vCenter Name>

$srcHost = Get-VMHost <Source Host Name>
$dstHost = Get-VMHost <Destination Host Name>

# Change the source and destination switch names if you need to
$srcSwitch = $srcHost | Get-VirtualSwitch -Name vSwitch0
$dstSwitch = $dstHost | Get-VirtualSwitch -Name vSwitch0

$srcPGs = $srcSwitch | Get-VirtualPortGroup
$dstSwitch = $dstHost | Get-VirtualSwitch -Name vSwitch1 -ErrorAction:SilentlyContinue
if ($dstSwitch -eq $null) {
  $dstSwitch = $dstHost | New-VirtualSwitch -Name $srcSwitch.Name
}

foreach ($srcPg in $srcPGs) {
  $pgName = $srcPg.name
  $pgVlan = $srcPg.VLanId

  $pgExists = $false
  foreach ($dstPg in $dstPGs) {
    if ($dstPg.Name -eq $pgName) {
      $pgExists = $true
    }
  }
  if (-not $pgExists) {
    #Write-Host "Creating portgroup $pgName with vlan $pgVlan"
    $dstSwitch | New-VirtualPortGroup -Name $pgName -VLanId $pgVlan
  }
}