Diagnose Network Problems In A Container Using The Filesystem

So you need to figure out why you application is not working, but your toolset is very limited because you are using either a minimal installation of Linux or you are in a container. This technique should work either way.

You can use the /dev filesystem to check network connections.

Example 1:
You would like to know if you can reach the host 172.16.0.10 on port 443.

ip=172.16.0.10
port=443
if $((echo > /dev/tcp/$ip/$port) &>/dev/null)
then echo "TCP port $port is open"
else echo "TCP port $port is closed"
fi

The above command will you the answer.

You can also write this as a one-liner

ip=172.16.0.10;port=443; (echo > /dev/tcp/$ip/$port) &>/dev/null && echo "TCP port $port is open" || echo "TCP port $port is closed"

Example 2:

You would like to know what connections are being made to and from the container or host, but you do not have netstat.

Continue reading Diagnose Network Problems In A Container Using The Filesystem

List VMs with Secure Boot enabled on Windows Server 2022

Since Microsoft released: KB5022842 a lot of customers has experienced Windows Server 2022 not being able to boot. On vSphere 7 this might be a problem if you have installed the patch at enabled secure boot for the server.

More information is available here: VMware KB90947

If you need to find VM that are running Windows Server 2022 and have enabled Secure Boot it is not that easy.

The problem is that your cannot always be sure that the OS selected for the VM is the OS actually installed in the VM. If for instance you installed Windows Server 2022 before is was officially supported in vSphere you might have chosen Windows Server 2019. So you will need to use the OS name that VMware tools are reporting.

But what is VMware tools is not running. That’s a problem.

The following script will find VMs with Secure Boot enabled that are running Windows Server 2022, but also VM’s where we are not certain because VMware Tools is not running.

Continue reading List VMs with Secure Boot enabled on Windows Server 2022

How To Make vRO Execute Python Code Blocks

vRealize Orchestrator (vRO) is a powerful automation platform that enables you to automate and orchestrate various IT processes, including the execution of Python scripts. In this article, we will show you how to set up vRO to run Python scripts and provide some tips along the way.

Prerequisites

Before you can run Python scripts in vRO, you need to have the following:

  • A working installation of vRealize Orchestrator (8.10.2+).
  • A vCloud Suite Advanced or Enterprise license. You cannot run Python scripts with the standard vCenter license for vRO

Setting up vRO to run Python scripts

To set up vRO to run Python scripts, follow these steps:

  • Open the vRealize Orchestrator client and log in with your administrator credentials. (https://<servername>/orchestration-ui)
  • In the main menu, go to the “Assets” and select “Environments” from the submenu.
  • Click the “New Environment” button to create a python3.7 environment.
  • In the “General” tab, enter a name and a description for the environment.
Continue reading How To Make vRO Execute Python Code Blocks

Reconnect ESXi host after reinstall

After a VMware ESXi host reinstall reconnecting your host is not as easy as changing the state of the host by using the Set-VMHost -State command in VMware PowerCLI. The reason is that your host has gotten a new certificate. So to do this scripted you need to retrieve the SSL thumbprint and specify that during the reconnect.

Continue reading Reconnect ESXi host after reinstall

Enable IPv6 using PowerCLI

This is a PowerCLI script to enable IPv6 on VMware ESXi hosts in you vCenter.

This problem is that disabling IPv6 in newer versions of ESXi can sometimes result in PSOD, so even if you are not using IPv6 in your environment, you should keep it enabled. https://kb.vmware.com/s/article/2150794

Import-Module VMware.PowerCLI

Connect-VIServer <Insert vCenter name>

$VMHost = Get-VMHost <insert hostname>

$esxcli = Get-EsxCli -VMHost $VMhost -V2
$argument = $esxcli.system.module.parameters.set.CreateArgs()
$argument.module = "tcpip4"
$argument.parameterstring = "ipv6=1"
$esxcli.system.module.parameters.set.Invoke($argument)
Write-Host "IPv6 Enabled for host: $($VMHost)"
Write-Host "You need to put the host in maintenance mode and reboot for changes to take effect."

Hope this helps you. Keep in mind that use of this script is entirely your responsibility, and you should always understand what a script does before you run it.

To detect which host that has IPv6 disabled check this post: https://vm.knutsson.it/?p=1193

Check if IPv6 is disabled

This is a PowerCLI script to list VMware ESXi host that has IPv6 disabled in you vCenter.

This problem is that disabling IPv6 in newer versions of ESXi can sometimes result in PSOD, so even if you are not using IPv6 in your environment, you should keep it enabled. https://kb.vmware.com/s/article/2150794

Import-Module VMware.PowerCLI

Connect-VIServer <Insert vCenter server FQDN>
$VMHosts = Get-VMHost | Sort-Object

foreach ($VMHost in $VMHosts) {
    if ($VMHost.ConnectionState -ne "Connected" ) { 
        $status = "Unknown. Host Status: $($VMHost.Connectionstate)"
        Write-host("$($VMHost): $($status)")
    } else {
        $value = ($VMHost | Get-VMHostModule tcpip4).Options
        if ($value -match "ipv6=1") {
            $status = "Enabled"
            #Write-host("$($VMHost): $($status)")
        } elseif ($value -match "ipv6=0") {
            $status = 'Disabled'
            Write-host("$($VMHost): $($status)")
        } else {
            $status = "Unknown"
            Write-host("$($VMHost): $($status) - $($value)")
        }
    }
}

Hope this helps you. Keep in mind that use of this script is entirely your responsibility, and you should always understand what a script does before you run it.

To enable IPv6 on hosts using PowerCLI check this post: https://vm.knutsson.it/?p=1198

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

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*)

Cross SSO and vCenter VMotion using PowerCLI

http://cloudmaniac.net/using-powercli-to-vmotion-vm-between-different-sso-domains-vcenters/

Roman Decker wrote an article about how to move virtual machine between vCenters that are not part of the same SSO domain, using PowerCLI.

I felt like it needed some adjustments to be more dynamic and interactive, so many of the hard coded bits I decided to make the script ask for at runtime.

Continue reading Cross SSO and vCenter VMotion using PowerCLI