Basically I need to do some host verification....
I want to report specifics for all servers that meet a G7 spec.
Specially, I need to know
The server name
Model number
Build number
Memory totals
BIOS date and version.
My PowerCli skills are really, really week. I have part of what I want in this code
$ESXHosts = Get-VMHost | where {$_.Model -match "ProLiant DL580 G7"} | Select-Object Name,Model,Build,MemoryTotalMB | Sort Name
I also see the code for BIOS versions is available:
Get-View -ViewType HostSystem | Select Name,@{N="BIOS version";E={$_.Hardware.BiosInfo.BiosVersion}},@{N="BIOS date";E={$_.Hardware.BiosInfo.releaseDate}}
However what I dont know is how to get both bits to go together. I am assuming that I need to somehow
Create a new object based on a host system
Create a new class with additional objects (ie BIOS)
Output that into a file.
How would I go about doing it ? For Bonus points I also need to find the driver version and firmware version of NIC 5, but again, no idea how to incorporate that.
I also would appreciate recomendations for a decent book that can bring me up to speed, but not at a slow slow pace. Any suggestions on that are welcome too
Get-VMHost | where {$_.Model -match "ProLiant DL580 G7"} | Select-Object Name,Model,Build,MemoryTotalMB, @{N="BIOS version";E={$_.ExtensionData.Hardware.BiosInfo.BiosVersion}},@{N="BIOS date";E={$_.ExtensionData.Hardware.BiosInfo.releaseDate}}, @{N="NIC5-pci";E={($_|Get-VMHostNetworkAdapter |?{$_.Name -eq 'vmnic5'}).ExtensionData.Driver } }, @{N='Driver Version';E={$driver_name=($_|Get-VMHostNetworkAdapter |?{$_.Name -eq 'vmnic5'}).ExtensionData.Driver;($_.Extensiondata.Runtime.HealthSystemRuntime.SystemHealt
hInfo.NumericSensorInfo | ?{$_.Name -like "${driver_name}*"}|select -unique).Name } }
This is for getting the driver version for the vmnic5 in the host as well. I mean it includes everything that you have written before that bonus
Regards,
Greg
PS. I don't know if have pasted it here without breaking lines. Basically make sure that this will be 1 line what i have pasted. I have tested this few seconds before on my G7 blades, and it works nice
Hi Stuart,
Get-VMHost | where {$_.Model -match "ProLiant DL580 G7"} | Select-Object Name,Model,Build,MemoryTotalMB, @{N="BIOS version";E={$_.ExtensionData.Hardware.BiosInfo.BiosVersion}},@{N="BIOS date";E={$_.ExtensionData.Hardware.BiosInfo.releaseDate}} | Sort Name
Get-VMHost | where {$_.Model -match "ProLiant DL580 G7"} | Select-Object Name,Model,Build,MemoryTotalMB, @{N="BIOS version";E={$_.ExtensionData.Hardware.BiosInfo.BiosVersion}},@{N="BIOS date";E={$_.ExtensionData.Hardware.BiosInfo.releaseDate}} | export-csv c:\report.csv
Get-VMHost | where {$_.Model -match "ProLiant DL580 G7"} | Select-Object Name,Model,Build,MemoryTotalMB, @{N="BIOS version";E={$_.ExtensionData.Hardware.BiosInfo.BiosVersion}},@{N="BIOS date";E={$_.ExtensionData.Hardware.BiosInfo.releaseDate}} | out-file c:\report.txt
Regards,
Greg
There are two books written about PowerCLI. "Managing VMware Infrastructure with Windows PowerShell TFM" by Hal Rottenberg. And "VMware vSphere PowerCLI Reference: Automating vSphere Administration" by Luc Dekens, Alan Renouf, Glenn Sizemore and Arnim van Lieshout. Both books are available via Amazon.
The first books gives a good introduction to PowerCLI. But it is a bit older and doesn't discuss the newer cmdlets. The second book is a more complete PowerCLI book. It also has it's own website: http://www.powerclibook.com/
Hi Greg,
That worked very well.
However how exactly does a get-view get put into a get-vmhost, if you see what I mean.
Get-VMHost | where {$_.Model -match "ProLiant DL580 G7"} | Select-Object Name,Model,Build,MemoryTotalMB, @{N="BIOS version";E={$_.ExtensionData.Hardware.BiosInfo.BiosVersion}},@{N="BIOS date";E={$_.ExtensionData.Hardware.BiosInfo.releaseDate}}, @{N="NIC5-pci";E={($_|Get-VMHostNetworkAdapter |?{$_.Name -eq 'vmnic5'}).ExtensionData.Driver } }, @{N='Driver Version';E={$driver_name=($_|Get-VMHostNetworkAdapter |?{$_.Name -eq 'vmnic5'}).ExtensionData.Driver;($_.Extensiondata.Runtime.HealthSystemRuntime.SystemHealt
hInfo.NumericSensorInfo | ?{$_.Name -like "${driver_name}*"}|select -unique).Name } }
This is for getting the driver version for the vmnic5 in the host as well. I mean it includes everything that you have written before that bonus
Regards,
Greg
PS. I don't know if have pasted it here without breaking lines. Basically make sure that this will be 1 line what i have pasted. I have tested this few seconds before on my G7 blades, and it works nice
Hi Stuart,
$ESXHosts = Get-VMHost | where {$_.Model -match "ProLiant DL580 G7"} | Select-Object Name,Model,Build,MemoryTotalMB | Sort Name
Get-View -ViewType HostSystem | Select Name,@{N="BIOS version";E={$_.Hardware.BiosInfo.BiosVersion}},@{N="BIOS date";E={$_.Hardware.BiosInfo.releaseDate}}
First you did something using the get-vmhost powercli command
then you were using vpshere api object -> this is the result of the get-view basically
So Most of the powercli commands returned objects have also data which is included in the vsphere objects as well.
They are put into the $_.ExtensionData
get-view -viewtype hostsystem -Filter @{'name'='host1'} | fl *
should look the same as
(get-vmhost host1).ExtensionData | fl *
It's just that using get-view from the beggining in most cases works way faster than using powercli cmdlets.
Get-VMHost | where {$_.Model -match "ProLiant DL580 G7"} | Select-Object Name,Model,Build,MemoryTotalMB, @{N="BIOS version";E={$_.ExtensionData.Hardware.BiosInfo.BiosVersion}},@{N="BIOS date";E={$_.ExtensionData.Hardware.BiosInfo.releaseDate}} | Sort Name
We do not put here any data from the get-view. I mean we are not using the get-view to obtain data. Instead, we are relying on the same data that is stored within the get-vmhost object. Becasue that object has $_.Extensiodata , which is exactly the same if get-view would give us. Then again, i just did not see point to use both of those methods here if i could use 1 and get all needed data.
Is this is the answer you were looking for ?
Let me know if something is still not clear for you.
Greg
Hi Greg,
That was very very useful indeed. I really appreciate that as it has just saved me inumerable hours (Think hundreds of hosts!) The explaination is a little clearer, but I need to read and re-read for it to sink in
Thanks
Stu
Hi Stuart,
don't worry, it takes time i guess to most of people to understand it. I also spent hours and hours to understand this.
Btw like RvdNieuwendijk wrote in his post, you could get those books, they are really helping to understand how this works. I have both of them , and i can tell you they are the best !
Greg
One last question, (please don't shoot me!)
Is there any way to get the shortname of the host, rather than the fqdn. I know the processing has to occur in the select loop, but not sure how to do it...
ie server1.myfqdn.com
would ideally be
server1
I know I can use the split command, but how do I work it in.
And the bigger question. Would it be possible to use XML to colour code it to alert to issues, ie the infamous 585 driver. So if the driver version is less than or not equal to nx_nic driver 4.0.602 it paints it red, and everything else green?
Cheers
Stu
Hi there,
Get-VMHost | where {$_.Model -match "ProLiant DL580 G7"} | Select-Object @{N='Name';E={($_.Name).split('.')[0]}} ,Model,Build,MemoryTotalMB, @{N="BIOS version";E={$_.ExtensionData.Hardware.BiosInfo.BiosVersion}},@{N="BIOS date";E={$_.ExtensionData.Hardware.BiosInfo.releaseDate}}, @{N="NIC5-pci";E={($_|Get-VMHostNetworkAdapter |?{$_.Name -eq 'vmnic5'}).ExtensionData.Driver } }, @{N='Driver Version';E={$driver_name=($_|Get-VMHostNetworkAdapter |?{$_.Name -eq 'vmnic5'}).ExtensionData.Driver;($_.Extensiondata.Runtime.HealthSystemRuntime.SystemHealt
hInfo.NumericSensorInfo | ?{$_.Name -like "${driver_name}*"}|select -unique).Name } }
@{N='Name';E={($_.Name).split('.')[0]}}
Get the name of the esx sadfsadfas.local.biz
use split on this, and split will divide the string using dot character
sadfsadfa
local
biz
Will return array with 3 rows, we are interested only in the host name so we that the [0] one.
About the colors , to be hoest i gues that would be hard now to transform it to write-host -foreground 😕
Maybe you can just do : |export-csv c:\report.csv
Open it in excel and do conditional formatting with colours.
But another hint, if you want to see only those which have particular bad driver version, you could still filter it using select , so instead of looking on all rows with good and wrong version, you would just query those which have wrong version . How about that ?
Greg