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 IP | model | cpu type | total cpu | cpu used | available cpu | total memory | used memory | available memory | total datastore size | used | available | total 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
Hello, Anishkumarv-
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?
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.
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?
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?
CpuTotalMhz | CpuUsageMhz | CputAvailableMhz |
31992 | 4075 | 27917 |
31980 | 2777 | 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
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?
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?
hostname | IP | Model | ProcessorType | CpuTotalMhz | CpuUsageMhz | CputAvailableMhz | MemoryTotalGB | MemoryUsageGB | MemAvailableGB | TotalDStoreSizeGB | DStoreUsedGB | DStoreAvailableGB | Cpu Count | PNicCount |
ESX-034 | 192.168.1.32 | ProLiant DL380 G7 | Intel(R) Xeon(R) CPU X5650 @ 2.67GHz | 31980 | 2716 | 29264 | 95.98997498 | 32.00585938 | 63.9841156 | 5025 | 2434.357422 | 2590.643 | 12 | 8 |
localhost | PowerEdge R510 | Intel(R) Xeon(R) CPU X5650 @ 2.67GHz | 31992 | 4645 | 27347 | 63.98394012 | 55.64355469 | 8.340385437 | 1671 | 1267.875 | 403.125 | 12 | 2 |
Need help on this thread.
Matt might be on a well deserved vacation
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
still i am getting same output. 😞 no luck , Ha Ha its a test esx so 🙂
Ha, LucD -- no vacation, but that sounds good -- I'll have to get to planning :smileylaugh:.
As for the problem, Anishkumarv, are you still having issue?