VMware Cloud Community
RajuVCP
Hot Shot
Hot Shot

Script to send output in email

Hi All,

It could be a simple, am not powercli expert. i was looking for a script to send the below commands output in email. the output content should send in email. The command will give us the list of VMs which need VM snapshot consolidation list. i want to connect multiple vCenter and run the command and send the output content in email.

Get-VM | where {$_.ExtensionData.Runtime.consolidationNeeded} | Select Name

Thank you in Advance.

Regards

RG

Raju Gunnal VCP 4, VCP 5, VTSP 4, VTSP 5, ITIL V3 http://www.techtosolution.com
Reply
0 Kudos
1 Reply
LucD
Leadership
Leadership

You could do something like this

$body = Get-VM | where {$_.ExtensionData.Runtime.consolidationNeeded} | Select Name | Out-String

if(-not $body){

    $body = 'No VMs found'

}

$sMail = @{

    To = 'to@domain'

    From = 'from@domain'

    Subject = 'My Subject'

    SmtpServer = 'mail.domain'

    Body = $body

}

Send-MailMessage @sMail


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos