VMware Cloud Community
jethroian_824
Contributor
Contributor

How to insert the code into my script to add Name and Host Version & Build number? Ta

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

===========================================================================

Reply
0 Kudos
5 Replies
LucD
Leadership
Leadership

Try like this

$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,

   @{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

Reply
0 Kudos
jethroian_824
Contributor
Contributor

Hello LuCD, unfortunately, there is no content upon receiving the email report. Ta

Reply
0 Kudos
LucD
Leadership
Leadership

Seems to be working for me.

Do you see the column when you just do

$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>

"@


$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

Reply
0 Kudos
jethroian_824
Contributor
Contributor

Hello LucD,

Here is the output.

VMHostVendorNameHost Version & Build VersionProductNameSerialNumber
x.x.x.xDell Inc.VMware ESXi 5.5.0 build-1331820PowerEdge R520xxxxxxx

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!

Reply
0 Kudos
LucD
Leadership
Leadership

Looks like you added the ESXi nodes with their IP address, not their hostname.

But try this variation.

$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>

"@


$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

Reply
0 Kudos