Nested ESXi on vSAN – PowerCLI to the rescue

I’m working on building out a nested lab environment on top of vSAN. I immediately thought of the last time I tried this, where I ran into all sorts of issues, luckily William Lam had already discovered a fix

I wanted to apply this to our new lab environment with quite a few hosts, and didn’t want to do it manually. Time to dust off my PowerCLI skills. No warranty provided.

The first step is obviously to ensure you have PowerCLI installed on your platform of choice. It’s a lot easier than I remembered, one command to get started.

Install-Module -Name VMware.PowerCLI                     

Next step is to connect to your vCenter server

connect-viserver -server "YourServer"

I then threw together get-vsan-scsi.ps1, shown below

clear

#Get all clusters in vCenter
$clusterlist = get-cluster | select Name | sort name

#Enumerate clusters
foreach ($cluster in $clusterlist)
    {
    $clustername = $cluster.name
    write-host "Checking vSAN.FakeSCSIReservations for $clustername" -BackgroundColor blue
    $hosts = get-cluster $cluster.name | get-vmhost
    #Enumerate hosts for the cluster
    Foreach ($VMhost in $hosts) 
        {
        #Check the advanced parameter
        $scsi = Get-AdvancedSetting -Entity $VMhost -Name "VSAN.FakeSCSIReservations"
        write-host "$vmhost setting is $scsi"
        }
    }

This should return all the clusters in your connected vCenter server, with the hosts within those clusters listed.

If you want to change the advanced parameter, you can use the script I created below. Note the “-whatif:$true” at the end of line 26. Comment this out if you want it to actually change anything.

clear

#Get all clusters in vCenter
$clusterlist = get-cluster | select Name | sort name

write-host "This script will change an advanced parameter to allow/disallow nested ESXi on vSAN storage"
write-host "Enter 0 to set the parameter to default (disallow), or 1 to allow"
$parameter = read-host "Enter 0 or 1"

#Confirm valid input
if ($parameter -eq "0" -or $parameter -eq "1")
    {
    #Enumerate clusters
    foreach ($cluster in $clusterlist)
        {
        $clustername = $cluster.name
        write-host "Setting vSAN.FakeSCSIReservations for $clustername" -BackgroundColor blue
        $hosts = get-cluster $cluster.name | get-vmhost
        #Enumerate hosts for the cluster
        Foreach ($VMhost in $hosts) 
            {
            #Check the advanced parameter
            $scsi = Get-AdvancedSetting -Entity $VMhost -Name "VSAN.FakeSCSIReservations"
            write-host "$vmhost setting is currently $scsi" -BackgroundColor red
            #Setting the advanced parameter
            $changescsi = Get-AdvancedSetting -Entity $VMhost -Name "VSAN.FakeSCSIReservations" | Set-AdvancedSetting -Value "$parameter" -Confirm:$false #-WhatIf:$true
            #Check the advanced parameter again
            $scsi = Get-AdvancedSetting -Entity $VMhost -Name "VSAN.FakeSCSIReservations"
            write-host "$vmhost setting is now $scsi" -BackgroundColor DarkGreen
            }
        }
    }

    else
        {
        write-host "Incorrect input"
        }

You should see something like this. Good luck!