Hi,
i have a script doing some extraction to check if there is snapshot, and show the date created, age of days…
i need to convert it to html and email out. i ran the script and the email has totally white blank body… not sure where is wrong / well, i am also not sure if i am doing it correctly…
p.s: i edited an existing script to my own though…
Get script path for later
$PSScriptRoot = $MyInvocation.MyCommand.Definition
$scriptinfo = “<br/><br/><font face=verdana size=-2>Script $PSScriptRoot running from $env:COMPUTERNAME</font>”
$ScriptCommonName = “VM Snapshot Check”
$timestamp = Get-Date -format dd-MM-yyyy
$MaintenanceCount = 0
$UnregisteredCount = 0
#Create HTML Header
$head = ‘<style>
META{http-equiv:refresh content:30;}
BODY{font-family:Verdana;}
TABLE{border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;}
TH{font-size:10px; border-width: 1px;padding: 6px;border-style: solid;border-color: black;background-color:LightSteelBlue}
TD{font-size:10px; border-width: 1px;padding: 6px;border-style: solid;border-color: black;background-color:GhostWhite}
</style>’
Assign email(s) to $sendto and SMTP server to $SMTPsrv
$sendto = “abc@xyz.co”
$SMTPsrv = “mail.server.com”
$subject = “[CHECKS] Virtual machine snapshot – $timestamp”
connecting to V-Center
$credential = get-vicredentialstoreitem -file E:\script\credentialstored.cred
set-powercliconfiguration -invalidcertificateaction ignore -confirm:$false
Connect-VIServer -Server $credential.host -user $credential.user -password $credential.password
write-host “Connected”
write-host “Checking VM Snapshot”
Get-VM | Get-Snapshot | select vm, name, created, @{Label=“Age”;Expression={($.created - [datetime]::Now).days}},@{Label=“Size”;Expression={[math]::Round($.SizeGB,2)}} | sort @{expression=“Age”} | format-table
Write-host “Complete” -Foregroundcolor Green
$messageParameters = @{
Subject = $subject
Body = $body + $scriptinfo
From = “scriptcheck@xyz.co”
To = $sendto
SmtpServer = “$SMTPsrv”
}
Send e-mail with Server load data
Send-MailMessage @messageParameters -BodyAsHtml