any idea why this is not working?
$report = get-snapshot -vm (get-vm) | select VM, name, description, powerstate | ft -autosize
$emailFrom = "vcenter@domain.com"
$emailTo = "vcenteradmins@domain.com"
$subject = "List of VMs with Snapshots"
$smtpServer = "send.domain.com"
$smtp = new-object Net.Mail.SmtpClient($smtpServer)
$smtp.Send($emailFrom, $emailTo, $subject, $Report)
-------------------------------------------------------------------------------------
I get an email like this
Microsoft.PowerShell.Commands.Internal.Format.FormatStartData Microsoft.PowerShell.Commands.Internal.Format.GroupStartData Microsoft.PowerShell.Commands.Internal.Format.FormatEntryData Microsoft.PowerShell.Commands.Internal.Format.FormatEntryData Microsoft.PowerShell.Commands.Internal.Format.FormatEntryData Microsoft.PowerShell.Commands.Internal.Format.FormatEntryData Microsoft.PowerShell.Commands.Internal.Format.FormatEntryData Microsoft.PowerShell.Commands.Internal.Format.FormatEntryData Microsoft.PowerShell.Commands.Internal.Format.FormatEntryData Microsoft.PowerShell.Commands.Internal.Format.FormatEntryData Microsoft.PowerShell.Commands.Internal.Format.FormatEntryData Microsoft.PowerShell.Commands.Internal.Format.FormatEntryData Microsoft.PowerShell.Commands.Internal.Format.FormatEntryData Microsoft.PowerShell.Commands.Internal.Format.FormatEntryData Microsoft.PowerShell.Commands.Internal.Format.FormatEntryData Microsoft.PowerShell.Commands.Internal.Format.FormatEntryData Microsoft.PowerShell.Commands.Internal.Format.FormatEntryData Microsoft.PowerShell.Commands.Internal.Format.FormatEntryData
$report = get-snapshot -vm (get-vm) | select VM, name, description, powerstate |out-string
$emailFrom = ""
$emailTo = ""
$subject = "List of VMs with Snapshots"
$smtpServer = ""
$smtp = new-object Net.Mail.SmtpClient($smtpServer)
$smtp.Send($emailFrom, $emailTo, $subject, $report.tostring())
remove the | ft -autosize
but you could also use my script
Getting all Snapshots with Powershell | VPXA – the virtualization blog
removing ft- autosize gave me a blank report
but $report does shows my vms
any idea?
$report = get-snapshot -vm (get-vm) | select VM, name, description, powerstate |out-string
$emailFrom = ""
$emailTo = ""
$subject = "List of VMs with Snapshots"
$smtpServer = ""
$smtp = new-object Net.Mail.SmtpClient($smtpServer)
$smtp.Send($emailFrom, $emailTo, $subject, $report.tostring())
thank you
you're welcome
the Net.Mail.SmtpClient($smtpServer) object only accepts strings. so you have to convert the $report var to a string...
is there quick way to convert it to html with convertto-html?
$report = get-snapshot -vm (get-vm) | select VM, name, description, powerstate |convertto-html
$emailFrom = ""
$emailTo = ""
$subject = "List of VMs with Snapshots"
$smtpServer = ""
$smtp = new-object Net.Mail.SmtpClient($smtpServer)
# This is an old .Net method
#$smtp.Send($emailFrom, $emailTo, $subject, $report.tostring())
Send-MailMessage -bodyashtml:$true -Body "$report" -from $emailfrom -SmtpServer $SMTPServer -Subject $Subject -To $emailTo