VMware Cloud Community
Hossy923
Contributor
Contributor

Get System Boot Device

I know you can get the system boot device using ESXCLI like this:

esxcli system boot device get

   Boot Filesystem UUID:
   Boot NIC: 01-23-45-67-89-ab-cd
   Stateless Boot NIC:

or you can do ESXCLI via PowerCLI like this:

(Get-VMHost myserver | Get-EsxCli).system.boot.device.get()

BootFilesystemUUID         BootNIC                    StatelessBootNIC
------------------         -------                    ----------------
                           01-23-45-67-89-ab-cd

But, how do you get this information from within PowerCLI without needing to use ESXCLI?

Is it available somewhere under the host object like in ExtensionData?

Is it in some hidden corner you can only access with Get-View?

0 Kudos
5 Replies
LucD
Leadership
Leadership

Not afaik, there is some info available through the HostBootDeviceSystem manager, but that is rather limited.

Check it out

foreach($esx in Get-VMHost) {
  $bmgr = Get-View $esx.ExtensionData.ConfigManager.BootDeviceSystem
 
$bootdevs = $bmgr.QueryBootDevices()   $current = $bootdevs.currentBootDeviceKey
  $bootdevs.BootDevices |   Select @{N="VMHost";E={$esx.Name}},Desscription,
    @{N="Current";E={if($_.Key -eq $current){$true}else{$false}}} }


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Hossy923
Contributor
Contributor

Thanks for the reply LucD.  I tried your code, but am getting an error on Get-View.

Get-View : Cannot validate argument on parameter 'VIObject'. The argument is null or empty. Supply an argument that is not null or empty and then try the command again.
At line:2 char:19
+   $bmgr = Get-View <<<<  $esx.ExtensionData.ConfigManager.BootDeviceSystem
    + CategoryInfo          : InvalidData: (:) [Get-View], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationError,VMware.VimAutomation.ViCore.Cmdlets.Commands.DotNetInterop.GetVIView


You cannot call a method on a null-valued expression.
At line:3 char:37
+   $bootdevs = $bmgr.QueryBootDevices <<<< ()
    + CategoryInfo          : InvalidOperation: (QueryBootDevices:String) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

  It appears the BootDeviceSystem property has no data.

PowerCLI C:\> $vmh.ExtensionData.ConfigManager|fl



CpuScheduler              : HostCpuSchedulerSystem-cpuScheduler-38348
DatastoreSystem           : HostDatastoreSystem-datastoreSystem-38348
MemoryManager             : HostMemorySystem-memorySystem-38348
StorageSystem             : HostStorageSystem-storageSystem-38348
NetworkSystem             : HostNetworkSystem-networkSystem-38348
VmotionSystem             : HostVMotionSystem-vmotionSystem-38348
VirtualNicManager         : HostVirtualNicManager-virtualNicManager-38348
ServiceSystem             : HostServiceSystem-serviceSystem-38348
FirewallSystem            : HostFirewallSystem-firewallSystem-38348
AdvancedOption            : OptionManager-EsxHostAdvSettings-38348
DiagnosticSystem          : HostDiagnosticSystem-diagnosticSystem-38348
AutoStartManager          : HostAutoStartManager-autoStartManager-38348
SnmpSystem                :
DateTimeSystem            : HostDateTimeSystem-dateTimeSystem-38348
PatchManager              : HostPatchManager-patchManager-38348
ImageConfigManager        : HostImageConfigManager-imageConfigManager-38348
BootDeviceSystem          :
FirmwareSystem            : HostFirmwareSystem-firmwareSystem-38348
HealthStatusSystem        : HostHealthStatusSystem-healthStatusSystem-38348
PciPassthruSystem         : HostPciPassthruSystem-pciPassthruSystem-38348
LicenseManager            :
KernelModuleSystem        : HostKernelModuleSystem-kernelModuleSystem-38348
AuthenticationManager     : HostAuthenticationManager-authenticationManager-383
                            48
PowerSystem               : HostPowerSystem-powerSystem-38348
CacheConfigurationManager : HostCacheConfigurationManager-cacheConfigManager-38
                            348
EsxAgentHostManager       : HostEsxAgentHostManager-esxAgentHostManager-38348
IscsiManager              : IscsiManager-iscsiManager-38348
LinkedView                :
DynamicType               :
DynamicProperty           :

0 Kudos
LucD
Leadership
Leadership

It seems that this is indeed the case in vSphere 5.*.

Then Get-EsxCli will be the only solution I'm afraid. Why don't you want to use that cmdlet if I might ask ?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Hossy923
Contributor
Contributor

I was hoping to avoid the additional processing time and connection time.  I have an Auto Deploy environment that uses stateless caching and one of the checks I want to start doing is to make sure all servers actually PXE booted versus using the local cache (a problem I've seen lately that I'm troubleshooting).

0 Kudos
Hossy923
Contributor
Contributor

Thanks, LucD, for your replies.

I ultimately ended up with the following code to run through all hosts:

Function HostBootCheck {
    Get-VMHost | Sort-Object -Property Name | ForEach-Object {
        $vmhostname = $_.Name
        $esxcli = $null
        $esxcli = $_ | Get-EsxCli -ErrorAction SilentlyContinue
        If ($esxcli -ne $null) {
            Try {
                $result = $esxcli.system.boot.device.get()
                If ($result.BootFilesystemUUID -ne '') { $vmhostname + ' booted from disk (' + $result.BootFilesystemUUID + ')' }
                If ($result.BootNIC -ne '') { $vmhostname + ' booted from the network (' + $result.BootNIC + ')' }
            }
            Catch {
                $vmhostname + ': Boot device info unavailable'
            }
        } Else {
            $vmhostname + ': Server unavailable'
        }
    }
}
0 Kudos