VMware Cloud Community
Anishkumarv
Enthusiast
Enthusiast

ESX / DATASTORE details in inventory list.

Hi all,

Thanks in advance for all volunteers who helped me to understand little bit about power cli. today i came with a different topic in power cli. how to get the esx/ details and datastore details in one script, for example my requirement is .

ESX hostname ESX IPmodel cpu typetotal cpucpu usedavailable cputotal memoryused memoryavailable memorytotal datastore sizeused availabletotal nic

this details i need in one script. I am also trying to sort out this details using get-vmhost , get-datastores but i am not able to get the output exactly what i expect . so kindly help me to solve this thread.

With Regards

Anish Kumar.V

10 Replies
mattboren
Expert
Expert

Hello, -

Several of those can be had via the normal properties returned from Get-VMHost, and the rest you can pretty much get with calculated properties.  Like:

Get-VMHost | Foreach-Object {
   
## get the GenericMeasureInfo for this host's datastores, to be used for the output
    $mioThisHostsDStoreInfo = Get-Datastore -VMHost $_ | Measure-Object -Property CapacityGB,FreeSpaceGB -Sum
   
$dblCapGB = ($mioThisHostsDStoreInfo | ?{$_.Property -eq "CapacityGB"}).Sum        ## datastore capacity
    $dblFreeGB = ($mioThisHostsDStoreInfo | ?{$_.Property -eq "FreeSpaceGB"}).Sum    ## datastore free
    Select -InputObject $_ @{n="hostname"; e={$_.NetworkInfo.HostName}},
        @{n
="IP"; e={($_.NetworkInfo.VirtualNic | ?{$_.ManagementTrafficEnabled -eq $true -and $_.IP}).IP}},
        Model,ProcessorType,CpuTotalMhz,CpuUsageMhz,
        @{n
="CputAvailableMhz"; e={$_.CpuTotalMhz - $_.CpuUsageMhz}},MemoryTotalGB,MemoryUsageGB,
        @{n
="MemAvailableGB"; e={$_.MemoryTotalGB - $_.MemoryUsageGB}},
        @{n
="TotalDStoreSizeGB"; e={$dblCapGB}},
        @{n
="DStoreUsedGB"; e={$dblCapGB - $dblFreeGB}},
        @{n
="DStoreAvailableGB"; e={$dblFreeGB}},
        @{n
="PNicCount"; e={($_.NetworkInfo.PhysicalNic | Measure-Object).Count}}
}
## end foreach-object

Note about the datastore space:  handling uncommitted space (due to thin virtual disks) is not covered here, but you can add that in.

How does that do for you?

Reply
0 Kudos
Anishkumarv
Enthusiast
Enthusiast

Get-VMHost | Foreach-Object {

    ## get the GenericMeasureInfo for this host's datastores, to be used for the output

    $mioThisHostsDStoreInfo = Get-Datastore -VMHost $_ | Measure-Object -Property CapacityGB,FreeSpaceGB -Sum

    $dblCapGB = ($mioThisHostsDStoreInfo | ?{$_.Property -eq "CapacityGB"}).Sum        ## datastore capacity

    $dblFreeGB = ($mioThisHostsDStoreInfo | ?{$_.Property -eq "FreeSpaceGB"}).Sum    ## datastore free

    Select -InputObject $_ @{n="hostname"; e={$_.NetworkInfo.HostName}},

        @{n="IP"; e={($_.NetworkInfo.VirtualNic | ?{$_.ManagementTrafficEnabled -eq $true -and $_.IP}).IP}},

        Model,ProcessorType,CpuTotalMhz,CpuUsageMhz,

        @{n="CputAvailableMhz"; e={$_.CpuTotalMhz - $_.CpuUsageMhz}},MemoryTotalGB,MemoryUsageGB,

        @{n="MemAvailableGB"; e={$_.MemoryTotalGB - $_.MemoryUsageGB}},

        @{n="TotalDStoreSizeGB"; e={$dblCapGB}},

        @{n="DStoreUsedGB"; e={$dblCapGB - $dblFreeGB}},

        @{n="DStoreAvailableGB"; e={$dblFreeGB}},

        @{n="PNicCount"; e={($_.NetworkInfo.PhysicalNic | Measure-Object).Count}}

} ## end foreach-object

Export-Csv -Path "VMs.csv" -NoTypeInformation -UseCulture

i am not able to export the output into csv file and i dnt know what you mean here " uncommited space" using  your script i can get the total , free and available spaces also.

Reply
0 Kudos
mattboren
Expert
Expert

Hello-

You can use the "call" operator (the ampersand -- "&") and a script block (a set of curly braces -- "{  }") to get the output to the pipeline, and on to Export-Csv (or whatever else you choose), like:

&{
Get-VMHost | Foreach-Object {
   
## get the GenericMeasureInfo for this host's datastores, to be used for the output
    $mioThisHostsDStoreInfo = ...
    ...
}
## end foreach-object
} | Export-Csv -Path "VMs.csv" -NoTypeInformation -UseCulture

Note the &{ at the start, and the additional } after the close of the Foreach-Object statement (and, I left the body of the Foreach-Object statement out -- that should just be the same as the previous post I made, but I left it off here to help highlight what is actually different).

And, the "uncommitted space":  that is just a separate statistic that lets you know how much additional disk _might_ be used, if there are thin virtual disks on the datastores (referring to how much space they have been allocated but that they have not yet used).  You are correct, those other three values are present, and you needn't use/report on uncommitted.  I was just pointing it out, in case thin provisioning is in play.

Anyway, how does that do?

Anishkumarv
Enthusiast
Enthusiast

Thanks dude,

its work like charm, but i have one doubt if i execute this command to check the physical cpu

Get-VMHost | Select Name, NumCPU

iam getting output 12

my doubt 1 physical cpu = how many virtual cpu?

CpuTotalMhzCpuUsageMhzCputAvailableMhz
31992407527917
319802777

29203

cputotalMhz -- its refering cpu speed?

i am little bit confused with cputotalMhz vs numcpu .. can you please help me to understand.

Thanks in advance

Reply
0 Kudos
mattboren
Expert
Expert

Hello-

Good to hear.

As for the NumCPU property:  that seems to be the number of CPU cores in the VMHost.  For example, a VMHost with two (2) 4-core processors should show "8" for its NumCPU property.

As for CpuTotalMhz:  that is the sum of the speeds of all of the cores, in MHz.  So, in the 2 4-core processor example, if those cores were each 3.2 GHz (3200 MHz), then the CpuTotalMhz should be 8 cores X 3200 MHz = 25600 total MHz.  That help to clarify, or do you still have question?

Anishkumarv
Enthusiast
Enthusiast

Thanks alot,

You are legend.

when i execute the script every time i am getting the warning messages.

WARNING: The 'VirtualNic' property of VMHostNetworkInfo type is deprecated. Use

'Get-VMHostNetworkAdapter' cmdlet instead.

WARNING: The 'PhysicalNic' property of VMHostNetworkInfo type is deprecated. Use

'Get-VMHostNetworkAdapter' cmdlet instead.

like this and in the output. for second esx host not able to get the ip address like this most of the esx i am not able to get, but. through command i can get ..is this a script error?? or any bug?

hostnameIPModelProcessorTypeCpuTotalMhzCpuUsageMhzCputAvailableMhzMemoryTotalGBMemoryUsageGBMemAvailableGBTotalDStoreSizeGBDStoreUsedGBDStoreAvailableGBCpu CountPNicCount
ESX-034192.168.1.32ProLiant DL380 G7Intel(R) Xeon(R) CPU X5650  @ 2.67GHz3198027162926495.9899749832.0058593863.984115650252434.3574222590.643128
localhost PowerEdge R510Intel(R) Xeon(R) CPU X5650  @ 2.67GHz3199246452734763.9839401255.643554698.34038543716711267.875403.125122
Reply
0 Kudos
Anishkumarv
Enthusiast
Enthusiast

Need help on this thread.

Reply
0 Kudos
LucD
Leadership
Leadership

Matt might be on a well deserved vacation Heart

You can safely ignore the warnings (for now).

Could it be that the ESXi called localhost has more than 1 Management Interface ?

Try changing that line like this

@{n="IP"; e={[string]::Join(',',($_.NetworkInfo.VirtualNic | ?{$_.ManagementTrafficEnabled -eq $true -and $_.IP} | %{$_.IP}))}}

PS: who decided to name that host 'localhost' ?


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

Reply
0 Kudos
Anishkumarv
Enthusiast
Enthusiast

still i am getting same output. 😞 no luck , Ha Ha its a test esx so 🙂

Reply
0 Kudos
mattboren
Expert
Expert

Ha,

Reply
0 Kudos