Automation

 View Only
  • 1.  Script to send output in email

    Posted Jul 22, 2020 05:07 PM

    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



  • 2.  RE: Script to send output in email

    Posted Jul 22, 2020 05:34 PM

    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