PowerCLI

 View Only
  • 1.  ESXI booting from Direct LUN or Local disk or USB

    Posted Sep 01, 2025 11:32 AM
      |   view attached

    Hi Lucd,

    I required one help..Since we are migrating all ESXI to 8, Wanted to get information for Multiple ESXI like whether they are booting from Local DISK or SAN LUN.

    Earlier below Script use work and I got from William Site, currently it is not throwing any error nor getting output.

    Below is the Script

    Function Get-ESXiBootDevice {
    <#
        .NOTES
        ===========================================================================
         Created by:    William Lam
         Organization:  VMware
         Blog:          www.williamlam.com
         Twitter:       @lamw
            ===========================================================================
        .DESCRIPTION
            This function identifies how an ESXi host was booted up along with its boot
            device (if applicable). This supports both local installation to Auto Deploy as
            well as Boot from SAN.
        .PARAMETER VMHostname
            The name of an individual ESXi host managed by vCenter Server
        .EXAMPLE
            Get-ESXiBootDevice
        .EXAMPLE
            Get-ESXiBootDevice -VMHostname esxi-01
    #>
        param(
            [Parameter(Mandatory=$false)][String]$VMHostname
        )
     
        if($VMHostname) {
            $vmhosts = Get-VMhost -Name $VMHostname
        } else {
            $vmhosts = Get-VMHost
        }
     
        $results = @()
        foreach ($vmhost in ($vmhosts | Sort-Object -Property Name)) {
            $esxcli = Get-EsxCli -V2 -VMHost $vmhost
            $bootDetails = $esxcli.system.boot.device.get.Invoke()
     
            # Check to see if ESXi booted over the network
            $networkBoot = $false
            if($bootDetails.BootNIC) {
                $networkBoot = $true
                $bootDevice = $bootDetails.BootNIC
            } elseif ($bootDetails.StatelessBootNIC) {
                $networkBoot = $true
                $bootDevice = $bootDetails.StatelessBootNIC
            }
     
            # If ESXi booted over network, check to see if deployment
            # is Stateless, Stateless w/Caching or Stateful
            if($networkBoot) {
                $option = $esxcli.system.settings.advanced.list.CreateArgs()
                $option.option = "/UserVars/ImageCachedSystem"
                try {
                    $optionValue = $esxcli.system.settings.advanced.list.Invoke($option)
                    $bootType = $optionValue.StringValue
                } catch {
                    $bootType = "stateless"
                }
            }
     
            # Loop through all storage devices to identify boot device
            $devices = $esxcli.storage.core.device.list.Invoke()
            $foundBootDevice = $false
            foreach ($device in $devices) {
                if($device.IsBootDevice -eq $true) {
                    $foundBootDevice = $true
     
                    if($device.IsLocal -eq $true -and $networkBoot -and $bootType -ne "stateful") {
                        $bootType = "stateless caching"
                    } elseif($device.IsLocal -eq $true -and $networkBoot -eq $false) {
                        $bootType = "local"
                    } elseif($device.IsLocal -eq $false -and $networkBoot -eq $false) {
                        $bootType = "remote"
                    }
     
                    $bootDevice = $device.Device
                    $bootModel = $device.Model
                    $bootVendor = $device.VEndor
                    $bootSize = $device.Size
                    $bootIsSAS = $device.IsSAS
                    $bootIsSSD = $device.IsSSD
                    $bootIsUSB = $device.IsUSB
                }
            }
     
            # Pure Stateless (e.g. No USB or Disk for boot)
            if($networkBoot-and $foundBootDevice -eq $false) {
                $bootModel = "N/A"
                $bootVendor = "N/A"
                $bootSize = "N/A"
                $bootIsSAS = "N/A"
                $bootIsSSD = "N/A"
                $bootIsUSB = "N/A"
            }
     
            $tmp = [pscustomobject] @{
                Host = $vmhost.Name;
                Device = $bootDevice;
                BootType = $bootType;
                Vendor = $bootVendor;
                Model = $bootModel;
                SizeMB = $bootSize;
                IsSAS = $bootIsSAS;
                IsSSD = $bootIsSSD;
                IsUSB = $bootIsUSB;
            }
            $results+=$tmp
        }
        $results | FT -AutoSize
    }

    Kindly help me out at the earliest...Since little urgent.

    Thanks in Advance.

    Regards,

    Kumar.



    -------------------------------------------

    Attachment(s)

    ps1
    ESXiBootDevice.ps1   3 KB 1 version


  • 2.  RE: ESXI booting from Direct LUN or Local disk or USB

    Posted Sep 02, 2025 04:46 AM

    Hello - i just tested the script and it works fine for me.
    Try running it like this without the parameters and without the ability to add vmhosts and see if it changes anything

    	$vmhosts = Get-VMHost
        $results = @()
        foreach ($vmhost in ($vmhosts | Sort-Object -Property Name)) {
            $esxcli = Get-EsxCli -V2 -VMHost $vmhost
            $bootDetails = $esxcli.system.boot.device.get.Invoke()
    
            # Check to see if ESXi booted over the network
            $networkBoot = $false
            if($bootDetails.BootNIC) {
                $networkBoot = $true
                $bootDevice = $bootDetails.BootNIC
            } elseif ($bootDetails.StatelessBootNIC) {
                $networkBoot = $true
                $bootDevice = $bootDetails.StatelessBootNIC
            }
    
            # If ESXi booted over network, check to see if deployment
            # is Stateless, Stateless w/Caching or Stateful
            if($networkBoot) {
                $option = $esxcli.system.settings.advanced.list.CreateArgs()
                $option.option = "/UserVars/ImageCachedSystem"
                try {
                    $optionValue = $esxcli.system.settings.advanced.list.Invoke($option)
                    $bootType = $optionValue.StringValue
                } catch {
                    $bootType = "stateless"
                }
            }
    
            # Loop through all storage devices to identify boot device
            $devices = $esxcli.storage.core.device.list.Invoke()
            $foundBootDevice = $false
            foreach ($device in $devices) {
                if($device.IsBootDevice -eq $true) {
                    $foundBootDevice = $true
    
                    if($device.IsLocal -eq $true -and $networkBoot -and $bootType -ne "stateful") {
                        $bootType = "stateless caching"
                    } elseif($device.IsLocal -eq $true -and $networkBoot -eq $false) {
                        $bootType = "local"
                    } elseif($device.IsLocal -eq $false -and $networkBoot -eq $false) {
                        $bootType = "remote"
                    }
    
                    $bootDevice = $device.Device
                    $bootModel = $device.Model
                    $bootVendor = $device.VEndor
                    $bootSize = $device.Size
                    $bootIsSAS = $device.IsSAS
                    $bootIsSSD = $device.IsSSD
                    $bootIsUSB = $device.IsUSB
                }
            }
    
            # Pure Stateless (e.g. No USB or Disk for boot)
            if($networkBoot-and $foundBootDevice -eq $false) {
                $bootModel = "N/A"
                $bootVendor = "N/A"
                $bootSize = "N/A"
                $bootIsSAS = "N/A"
                $bootIsSSD = "N/A"
                $bootIsUSB = "N/A"
            }
    
            $tmp = [pscustomobject] @{
                Host = $vmhost.Name;
                Device = $bootDevice;
                BootType = $bootType;
                Vendor = $bootVendor;
                Model = $bootModel;
                SizeMB = $bootSize;
                IsSAS = $bootIsSAS;
                IsSSD = $bootIsSSD;
                IsUSB = $bootIsUSB;
            }
            $results+=$tmp
        }
        $results | FT -AutoSize
    
    -------------------------------------------



  • 3.  RE: ESXI booting from Direct LUN or Local disk or USB

    Posted Sep 02, 2025 08:41 AM

    Try as below. This works for me.

    Function Get-ESXiBootDevice {
    <#
        .DESCRIPTION
            Identify ESXi host boot device & type (local, remote, stateless etc.)
    #>
        param(
            [Parameter(Mandatory=$false)]
            [String]$VMHostname
        )
     
        if ($VMHostname) {
            $vmhosts = Get-VMhost -Name $VMHostname
        } else {
            $vmhosts = Get-VMHost
        }
     
        $results = @()
        foreach ($vmhost in ($vmhosts | Sort-Object -Property Name)) {
            $esxcli = Get-EsxCli -V2 -VMHost $vmhost
            $bootDetails = $esxcli.system.boot.device.get.Invoke()
     
            # --- Default values
            $bootDevice = "Unknown"
            $bootType   = "Unknown"
            $bootModel  = "Unknown"
            $bootVendor = "Unknown"
            $bootSize   = "Unknown"
            $bootIsSAS  = $null
            $bootIsSSD  = $null
            $bootIsUSB  = $null

            # Check if network boot
            $networkBoot = $false
            if ($bootDetails.BootNIC) {
                $networkBoot = $true
                $bootDevice  = $bootDetails.BootNIC
            } elseif ($bootDetails.StatelessBootNIC) {
                $networkBoot = $true
                $bootDevice  = $bootDetails.StatelessBootNIC
            }

            if ($networkBoot) {
                $option = $esxcli.system.settings.advanced.list.CreateArgs()
                $option.option = "/UserVars/ImageCachedSystem"
                try {
                    $optionValue = $esxcli.system.settings.advanced.list.Invoke($option)
                    $bootType = if ($optionValue.StringValue) { $optionValue.StringValue } else { "stateless" }
                } catch {
                    $bootType = "stateless"
                }
            }

            # Check storage devices
            $devices = $esxcli.storage.core.device.list.Invoke()
            $foundBootDevice = $false
            foreach ($device in $devices) {
                if ($device.IsBootDevice -eq $true) {
                    $foundBootDevice = $true

                    if ($device.IsLocal -eq $true -and $networkBoot -and $bootType -ne "stateful") {
                        $bootType = "stateless caching"
                    } elseif ($device.IsLocal -eq $true -and -not $networkBoot) {
                        $bootType = "local"
                    } elseif (-not $device.IsLocal -and -not $networkBoot) {
                        $bootType = "remote"
                    }

                    $bootDevice = $device.Device
                    $bootModel  = $device.Model
                    $bootVendor = $device.Vendor   # fixed
                    $bootSize   = $device.Size
                    $bootIsSAS  = $device.IsSAS
                    $bootIsSSD  = $device.IsSSD
                    $bootIsUSB  = $device.IsUSB
                }
            }

            # Pure stateless (no boot device)
            if ($networkBoot -and -not $foundBootDevice) {
                $bootModel  = "N/A"
                $bootVendor = "N/A"
                $bootSize   = "N/A"
                $bootIsSAS  = "N/A"
                $bootIsSSD  = "N/A"
                $bootIsUSB  = "N/A"
            }

            $results += [pscustomobject]@{
                Host    = $vmhost.Name
                Device  = $bootDevice
                BootType= $bootType
                Vendor  = $bootVendor
                Model   = $bootModel
                SizeMB  = $bootSize
                IsSAS   = $bootIsSAS
                IsSSD   = $bootIsSSD
                IsUSB   = $bootIsUSB
            }
        }
        return $results   # return objects instead of just Format-Table
    }

    Get-ESXiBootDevice | Format-Table -AutoSize

    -------------------------------------------



  • 4.  RE: ESXI booting from Direct LUN or Local disk or USB

    Posted Sep 02, 2025 01:41 PM

    FYI LucD retired

    -------------------------------------------