Hi Guys,
I've put together a simple script which emails a list of VM's with connected ISO's or CDROM's, the script seems to work ok i would just like some help with html formatting if possible, so the info is in a table, if someone hear with HTML skills could kindly help it would be much appreciated.
$report =get-vm | Where {($_.Name -notlike "ksv*")} | where {$_ | get-cddrive | where { $_.ConnectionState.Connected -eq "true" -and $_.ISOPath -like "*.ISO*"} } | select Name, @{Name=".ISO Path";Expression={(Get-CDDrive $_).isopath }}
Send-MailMessage -Subject "IOPS Report" -From vc@mail.com.au `
-To user@mail.com.au -SmtpServer 000.000.000.000 `
-BodyAsHtml -Body ($report | Select Name,.ISOPath | ConvertTo-html | Out-String
Hi,
I use following style for my reports. Works well for me. try this
# CSS stylesheet
$a = "<style>"
$a = $a + "BODY{background-color:Gainsboro;}"
$a = $a + "TABLE{border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;}"
$a = $a + "TH{border-width: 1px;padding: 5px;border-style: solid;border-color: black;background-color:SkyBlue}"
$a = $a + "TD{border-width: 1px;padding: 5px;border-style: solid;border-color: black;background-color:PaleTurquoise}"
$a = $a + "*{font-family: Verdana, Arial, Helvetica, sans-serif; font-size: small;}"
$a = $a + "</style>"
$report =get-vm | Where {($_.Name -notlike "ksv*")} | where {$_ | get-cddrive | where { $_.ConnectionState.Connected -eq "true" -and $_.ISOPath -like "*.ISO*"} } | select Name, @{Name=".ISO Path";Expression={(Get-CDDrive $_).isopath }}
$Report | ConvertTo-Html -head $a | Set-Content "<path to html file>"
ConvertTo-HTML has the -Head parameter that can be used to add style information to the HTML that it generates.
You can define $style or named it watever you want then state it as -Head after ConvertTo-Html
Like you can use script :
$style = "< style>BODY{font-family: Arial; font-size: 10pt;}"
$style = $style + "TABLE{border: 1px solid black; border-collapse: collapse;}"
$style = $style + "TH{border: 1px solid black; background: #dddddd; padding: 5px; }"
$style = $style + "TD{border: 1px solid black; padding: 5px; }"
$style = $style + "< /style>"
$report =get-vm | Where {($_.Name -notlike "ksv*")} | where {$_ | get-cddrive | where { $_.ConnectionState.Connected -eq "true" -and $_.ISOPath -like "*.ISO*"} } | select Name, @{Name=".ISO Path";Expression={(Get-CDDrive $_).isopath }}
Send-MailMessage -Subject "IOPS Report" -From vc@mail.com.au `
-To user@mail.com.au -SmtpServer 000.000.000.000 `
-BodyAsHtml -Body ($report | Select Name,.ISOPath | ConvertTo-Html -Head $style | Out-String
