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

HPE Amplifier Pack HSM has failed to unregister with vcenter

After upgrading from vCenter 6.7 to vCenter 7.0 you might experience that you HPE Amplifier Pack vLCM HSM can no longer communicate with vCenter.

When trying to edit you are told that it cannot complete the task, and you cannot delete the registration either.

Solution:
Remove the vLCM addon in ILO Amplifier Pack. This can be done if the ILO Amplifier Pack web interface under Configuration and Settings, under Add-On Service Manager.

First stop the Add-on, next remove it. Afterwards you can just choose to download it again.

All this is done at you own risk of course, but if worked for me.

Best of luck! Please let me know if it helped you.

PowerCLI: Get ESXi Hosts Version and Uptime

This is a quick and easy script to get all hosts from a vCenter sorted by Cluster and Host name. You will get the Cluster, Hostname, Version, Build and Uptime in days.

Connect-VIServer <vCenter FQDN>


$clusters = Get-Cluster | Sort-Object
$objects = @()

foreach ($cluster in $clusters) {
    Write-Host "Gathering from cluster: $($cluster.Name)"

    $vmhosts = $cluster | Get-VMHost | Sort-Object
    
    foreach ($vmhost in $vmhosts) {
        $object = New-Object -TypeName PSObject
        $object | Add-Member -MemberType NoteProperty -Name "Cluster" -Value $cluster
        $object | Add-Member -MemberType NoteProperty -Name "Host" -Value $vmhost
        $object | Add-Member -MemberType NoteProperty -Name "Version" -Value $vmhost.Version
        $object | Add-Member -MemberType NoteProperty -Name "Build" -Value $vmhost.Build
        $object | Add-Member -MemberType NoteProperty -Name "Uptime (Days)" -Value (New-TimeSpan -Start $vmhost.ExtensionData.Summary.Runtime.BootTime -End (Get-Date) | Select-Object -ExpandProperty Days)
        $objects += $object
    }
}

$objects | ft -AutoSize

vCenter services not starting after 6.7 Update 3f upgrade

After upgrading a 3 vCenter Enhanced Link Mode environment a customer experienced the following error:

Server is at a higher functional level (1) than partner (<partner vCenter server>)(0) and cannot perform at a lower level.

When checking the domain functional level of each of the three servers, they all state that they are at level 1. The other server are starting like normal.

One server is not starting the vmdir service and it is also that service that is reporting the error. Most of the other services on a vCenter is dependant on this the vmdir.

I do not have a solution as of now. I might have a reason for the issue, and I might have a workaround. VMware is currently trying to figure out how to fix this.

Continue reading vCenter services not starting after 6.7 Update 3f upgrade

vRA 8.1 Custom Resources

Todays announcement of vRealize Automation 8.1 reveals the possibility to use Custom resources in vRA.

I am super exited about that ability. Those who know me, knows that I am a HUGE fan of vRO (vRealize Orchestrator) and the possibility to add anything as a resource in a vRA really opens the product to so many possibilities.

Anything you can imagine, and that you can make vRO do, you can put in a blueprint.

Spoiler alert. New vRA 8.1 feature
Continue reading vRA 8.1 Custom Resources

vSphere 7 – Return of the blue folders

Back in the day it was customary to divide your VMs into three “blue” folders. I was not uncommon to see the three folders named High Priority, Normal Priority and Low Priority, and then people would distribute the VMs into those folders. The reason they were called blue folder was because it was really resource pools created in a DRS cluster in the Hosts and Clusters view in vCenter. And they were not made to logically divide you VMs into “folders”.

Spoiler Alert

New DRS Feature – Scalable SHares

The problem with this approach is that unless you regularly reconfigured these resource pools you would get unexpected performance. I was not uncommon for an installation to have 5-10% of the VMs in the high priority “folder”, 80% in the normal priority “folder” and 5-10% in the low priority “folder”. The problem with this is that if you then select High, Normal and Low shares for these folders, you will not get the performance you would expect.

Continue reading vSphere 7 – Return of the blue folders

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
  }
}