Does anyone know a way to generate a VM list from vcenter in a html format using a scripting language ? I can produce a csv version using powershell, just can't seem to find the html equivalent.
Thanks
Here is the PowerShell sample, including HTML styling to match your requirements (for example, embedding the report in a SharePoint site);
## ------------
## HTML STYLING
## ------------
$head = @"
<style type="text/css">
table {
font-family: Calibri;
font-size:13px;
color:#333333;
border-width: 1px;
border-color: #CCCCCC;
border-collapse: collapse;
padding-left: 5px;
}
th {
font-size:13px;
border-width: 1px;
padding: 5px;
border-style: solid;
border-color: #CCCCCC;
background-color: #223C76;
color:#ffffff;
text-align: left;
}
td {
border-width: 1px;
padding: 5px;
border-style: solid;
border-color: #CCCCCC;
}
h1 {
font-family: Calibri;
font-size:24px;
color: #9b1b1f;
}
font-family: Calibri;
font-size:13px;
color: #223C76;
}
font-family: Calibri;
font-size:12px;
color:#223C76;
}
tr:nth-child(odd) {
background-color: #f2f2f2;
}
</style>
“@
## Share path to output HTML results
$Path = '\\share'
## Path to CSV data that will be processed into HTML
$Final = Import-Csv -Path '\\share\Report.csv'
## Add some content before your HTML table
$Pre = '<h1>VM List Report</h1>'
$Pre += '<p class="smallheader">For any queries with this data, please contact <a href="mailto:jon@jonmunday.net">Jon Munday</a>.</p>'
$Pre += '<p class="smallheader"> [' + $Final.Count + ' objects found] - <a href="\\share\Report.csv">Export CSV</a> | Report generated: ' + (Get-Date -Format 'dd/MM/yy HH:mm:ss') + '</p>'
## Add some content after your HTML table
$Post = '<p class="footer">Report generated: ' + (Get-Date -Format 'dd/MM/yy HH:mm:ss') + '</p>'
## Create the HTML using the custom styling, pre and post content
$Final | ConvertTo-Html -title 'VM List'-Head $head -PreContent $Pre -PostContent $Post | Out-File "$Path\Report.html" -Confirm:$false #-Append
Hi Chris,
If you're using PowerShell, just pipe your CSV results to the ConvertTo-Html cmdlet. You can add custom styling using the -Head parameter.
I'll just put together a quick example and past the code in a follow up message.
Cheers,
Jon
Here is the PowerShell sample, including HTML styling to match your requirements (for example, embedding the report in a SharePoint site);
## ------------
## HTML STYLING
## ------------
$head = @"
<style type="text/css">
table {
font-family: Calibri;
font-size:13px;
color:#333333;
border-width: 1px;
border-color: #CCCCCC;
border-collapse: collapse;
padding-left: 5px;
}
th {
font-size:13px;
border-width: 1px;
padding: 5px;
border-style: solid;
border-color: #CCCCCC;
background-color: #223C76;
color:#ffffff;
text-align: left;
}
td {
border-width: 1px;
padding: 5px;
border-style: solid;
border-color: #CCCCCC;
}
h1 {
font-family: Calibri;
font-size:24px;
color: #9b1b1f;
}
font-family: Calibri;
font-size:13px;
color: #223C76;
}
font-family: Calibri;
font-size:12px;
color:#223C76;
}
tr:nth-child(odd) {
background-color: #f2f2f2;
}
</style>
“@
## Share path to output HTML results
$Path = '\\share'
## Path to CSV data that will be processed into HTML
$Final = Import-Csv -Path '\\share\Report.csv'
## Add some content before your HTML table
$Pre = '<h1>VM List Report</h1>'
$Pre += '<p class="smallheader">For any queries with this data, please contact <a href="mailto:jon@jonmunday.net">Jon Munday</a>.</p>'
$Pre += '<p class="smallheader"> [' + $Final.Count + ' objects found] - <a href="\\share\Report.csv">Export CSV</a> | Report generated: ' + (Get-Date -Format 'dd/MM/yy HH:mm:ss') + '</p>'
## Add some content after your HTML table
$Post = '<p class="footer">Report generated: ' + (Get-Date -Format 'dd/MM/yy HH:mm:ss') + '</p>'
## Create the HTML using the custom styling, pre and post content
$Final | ConvertTo-Html -title 'VM List'-Head $head -PreContent $Pre -PostContent $Post | Out-File "$Path\Report.html" -Confirm:$false #-Append
Thank you very much - this was by far more that I had hoped for. !!!!