VMware Cloud Community
ganapa2000
Hot Shot
Hot Shot
Jump to solution

issue with HTML output

Hi,

I am having issues in getting the output in html format

Get-VM -Name db1 -PipelineVariable vm |

ForEach-Object -Process {

    $_.guest.IPAddress |

    Select @{N='VM Name';E={$vm.Name}},

        @{N="IP Address";E={$_}}

}

From the above output, I would like to declare variable for name and ip address and would like to get the output

When I use the below method, I am getting blank

$VMInfo = $null

$VMInfo += "<th><center>VM Name</th><th><center>IP Address</th>"

Get-VM -Name db1 -PipelineVariable vm |

ForEach-Object -Process {

    $_.guest.IPAddress |

    Select $name = @{N='VM Name';E={$vm.Name}},

        $IP = @{N="IP Address";E={$_}}

}

$VMInfo += "<th><center>$Name</th><th><center>$IP</th>"

I have already have a HTML report, I would like to get this added along.

Please help!!!

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Since the script already produces HTML, there is no need to do the ConvertTo-Html.

The following are in fact some HTML remarks:

  • The data needs to go with the <td> tag, not <th> which is only for the header of the table
  • And you have to indicate what the rows are with <tr>

Something like this for example

$VMInfo = @()

$VMInfo += "<table>"

$VMInfo += "<tr><th><center>VM Name</th><th><center>IP Address</th></tr>"

Get-VM -Name db1 -PipelineVariable vm |

ForEach-Object -Process {

    $_.guest.IPAddress |

    ForEach-Object -Process {

        $VMInfo += "<tr><td><center>$($vm.Name)</td><td><center>$($_)</td>"

    }

}

$VMInfo += "</table>"

$VMInfo | Set-Content -Path .\report.html

Invoke-Item -Path .\report.html 


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

View solution in original post

0 Kudos
4 Replies
LucD
Leadership
Leadership
Jump to solution

You don't need to use the Select-Object for this.
Just handle the IP addresses in a ForEach loop, and use the values in a string.

Something like this

$VMInfo = $null

$VMInfo += "<th><center>VM Name</th><th><center>IP Address</th>"

Get-VM -Name db1 -PipelineVariable vm |

ForEach-Object -Process {

    $_.guest.IPAddress |

    ForEach-Object -Process {

        $VMInfo += "<th><center>$($vm.Name)</th><th><center>$($_)</th>"

    }

}


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

0 Kudos
ganapa2000
Hot Shot
Hot Shot
Jump to solution

Hi LucD,

Thanks a lot for your quick reply.

How can I get this exported to html file ?

I tried the below, it is not working

$VMInfo = $null

$VMInfo += "<th><center>VM Name</th><th><center>IP Address</th>"

Get-VM -Name db1 -PipelineVariable vm |

ForEach-Object -Process {

    $_.guest.IPAddress |

    ForEach-Object -Process {

        $VMInfo += "<th><center>$($vm.Name)</th><th><center>$($_)</th>" | ConvertTo-Html >> D:\report.html

    }

}

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Since the script already produces HTML, there is no need to do the ConvertTo-Html.

The following are in fact some HTML remarks:

  • The data needs to go with the <td> tag, not <th> which is only for the header of the table
  • And you have to indicate what the rows are with <tr>

Something like this for example

$VMInfo = @()

$VMInfo += "<table>"

$VMInfo += "<tr><th><center>VM Name</th><th><center>IP Address</th></tr>"

Get-VM -Name db1 -PipelineVariable vm |

ForEach-Object -Process {

    $_.guest.IPAddress |

    ForEach-Object -Process {

        $VMInfo += "<tr><td><center>$($vm.Name)</td><td><center>$($_)</td>"

    }

}

$VMInfo += "</table>"

$VMInfo | Set-Content -Path .\report.html

Invoke-Item -Path .\report.html 


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

0 Kudos
ganapa2000
Hot Shot
Hot Shot
Jump to solution

That Worked. Thank you very much Smiley Happy

0 Kudos