VMware Cloud Community
tdubb123
Expert
Expert
Jump to solution

snapshot report

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

0 Kudos
1 Solution

Accepted Solutions
brunofernandez1
Jump to solution

$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())

------------------------------------------------------------------------------- If you found this or any other answer helpful, please consider to award points. (use Correct or Helpful buttons) Regards from Switzerland, B. Fernandez http://vpxa.info/

View solution in original post

0 Kudos
7 Replies
brunofernandez1
Jump to solution

remove the | ft -autosize

but you could also use my script Smiley Happy

Getting all Snapshots with Powershell | VPXA – the virtualization blog

------------------------------------------------------------------------------- If you found this or any other answer helpful, please consider to award points. (use Correct or Helpful buttons) Regards from Switzerland, B. Fernandez http://vpxa.info/
0 Kudos
tdubb123
Expert
Expert
Jump to solution

removing ft- autosize gave me a blank report

but $report does shows my vms

any idea?

0 Kudos
brunofernandez1
Jump to solution

$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())

------------------------------------------------------------------------------- If you found this or any other answer helpful, please consider to award points. (use Correct or Helpful buttons) Regards from Switzerland, B. Fernandez http://vpxa.info/
0 Kudos
tdubb123
Expert
Expert
Jump to solution

thank you

0 Kudos
brunofernandez1
Jump to solution

you're welcome

the Net.Mail.SmtpClient($smtpServer) object only accepts strings. so you have to convert the $report var to a string...

------------------------------------------------------------------------------- If you found this or any other answer helpful, please consider to award points. (use Correct or Helpful buttons) Regards from Switzerland, B. Fernandez http://vpxa.info/
0 Kudos
tdubb123
Expert
Expert
Jump to solution

is there quick way to convert it to html with convertto-html?

0 Kudos
brunofernandez1
Jump to solution

$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

------------------------------------------------------------------------------- If you found this or any other answer helpful, please consider to award points. (use Correct or Helpful buttons) Regards from Switzerland, B. Fernandez http://vpxa.info/
0 Kudos