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!!!
Since the script already produces HTML, there is no need to do the ConvertTo-Html.
The following are in fact some HTML remarks:
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
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
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
}
}
Since the script already produces HTML, there is no need to do the ConvertTo-Html.
The following are in fact some HTML remarks:
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
That Worked. Thank you very much