I want to add the block code below into my script to get the hostname and esxi build number. How do I insert it? Ta
Get-View
-ViewType
HostSystem
-Property
Name,Config.Product |
Format-Table
Name, @{L=
'Host Version & Build Version'
;E={
$_
.Config.Product.FullName}}
OUTPUT:
Name Host Version & Build Version <======HOW to insert this column into my script below
---- ----------------------------
ESX01.PP2742.local VMware ESXi 5.1.0 build-1065491
ESX01.PP50300.local VMware ESXi 5.1.0 build-799733
==================================================================================
$user = 'hot'
$pswd = 'password'
$Path = "C:\Temp\vmhost.txt"
$xx = Get-Content -Path $Path
$srv = Connect-VIServer -Server $xx -User $user -Password $pswd
$Header = @"
<style>
TABLE {border-width: 1px; border-style: solid; border-color: black; border-collapse: collapse;}
TD {border-width: 1px; padding: 3px; border-style: solid; border-color: black;}
</style>
"@
#how to insert here
$report = foreach($esxcli in Get-VMHost | Get-EsxCli -V2){
$esxcli.hardware.platform.get.Invoke() |
Select @{N='VMHost';E={$esxcli.VMHost.Name}},VendorName,ProductName,SerialNumber
}
$sMail = @{
Body = $report | ConvertTo-Html -Head $Header | Out-String
BodyAsHtml = $true
To = 'xxx.gmail.com'
From = 'xxx.gmail.com'
Subject = 'ESXi Reports'
SmtpServer = 'x.x.x.x'
}
Send-MailMessage @sMail
===========================================================================
Try like this
$pswd = 'password'
$Path = "C:\Temp\vmhost.txt"
$xx = Get-Content -Path $Path
$srv = Connect-VIServer -Server $xx -User $user -Password $pswd
$Header = @"
<style>
TABLE {border-width: 1px; border-style: solid; border-color: black; border-collapse: collapse;}
TD {border-width: 1px; padding: 3px; border-style: solid; border-color: black;}
</style>
"@
#how to insert here
$report = foreach($esxcli in Get-VMHost | Get-EsxCli -V2){
$esxcli.hardware.platform.get.Invoke() |
Select @{N='VMHost';E={$esxcli.VMHost.Name}},VendorName,
@{N='Host Version & Build Version';E={$esxcli.VMHost.ExtensionData.Config.Product.FullName}},
ProductName,SerialNumber
}
$sMail = @{
Body = $report | ConvertTo-Html -Head $Header | Out-String
BodyAsHtml = $true
To = 'xxx.gmail.com'
From = 'xxx.gmail.com'
Subject = 'ESXi Reports'
SmtpServer = 'x.x.x.x'
}
Send-MailMessage @sMail
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hello LuCD, unfortunately, there is no content upon receiving the email report. Ta
Seems to be working for me.
Do you see the column when you just do
<style>
TABLE {border-width: 1px; border-style: solid; border-color: black; border-collapse: collapse;}
TD {border-width: 1px; padding: 3px; border-style: solid; border-color: black;}
</style>
"@
$report = foreach($esxcli in Get-VMHost | Get-EsxCli -V2){
$esxcli.hardware.platform.get.Invoke() |
Select @{N='VMHost';E={$esxcli.VMHost.Name}},VendorName,
@{N='Host Version & Build Version';E={$esxcli.VMHost.ExtensionData.Config.Product.FullName}},
ProductName,SerialNumber
}
$report | ConvertTo-Html -Head $Header | Out-String | Out-File -FilePath C:\Temp\test.html
invoke-item -Path C:\Temp\test.html
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hello LucD,
Here is the output.
VMHost | VendorName | Host Version & Build Version | ProductName | SerialNumber |
---|---|---|---|---|
x.x.x.x | Dell Inc. | VMware ESXi 5.5.0 build-1331820 | PowerEdge R520 | xxxxxxx |
One thing is missing though. The Name of Hostname of ESXi is missing on the column.
Name Host Version & Build Version
---- ----------------------------
ESX01.PP2742.local VMware ESXi 5.1.0 build-1065491
ESX01.PP50300.local VMware ESXi 5.1.0 build-799733
The goal is to send the reports via email once done.
Many thanks!
Looks like you added the ESXi nodes with their IP address, not their hostname.
But try this variation.
<style>
TABLE {border-width: 1px; border-style: solid; border-color: black; border-collapse: collapse;}
TD {border-width: 1px; padding: 3px; border-style: solid; border-color: black;}
</style>
"@
$report = foreach($esxcli in Get-VMHost | Get-EsxCli -V2){
$esxcli.hardware.platform.get.Invoke() |
Select @{N='VMHost';E={($esxcli.system.hostname.get.Invoke()).FullyQualifiedDomainName}},VendorName,
@{N='Host Version & Build Version';E={$esxcli.VMHost.ExtensionData.Config.Product.FullName}},
ProductName,SerialNumber
}
$report | ConvertTo-Html -Head $Header | Out-String | Out-File -FilePath C:\Temp\test.html
invoke-item -Path C:\Temp\test.html
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference