VMware Cloud Community
marco2601
Contributor
Contributor

Sen notification Mail

hi guys I have the following scrip I want that after the sentence "ELSE" is sent a notification email as I can do it?

----------------------------------------------------------------------------------------------------------------------------------------------------

##Sentencia para verificacion de conexion a VM origen

while($TRUE){

if (Test-Connection -ComputerName $VMIP -Delay 1 -quiet){

    Write-Host "$VMIP is up" -ForegroundColor Green

  }

  else{

Write-Host "$VMIP is down" -ForegroundColor Green

##Coneccion a vCenter

connect-viserver -server $vcenter_server -User $vcenter_user -Password $vcenter_pwd

#Nombre de la VM Origen

$VMorigen= "SRV-SIPSERVER"

#Nombre de la ultima VM clonada

$VMclone= "$($VMorigen)-$((Get-Date).ToString('MMddyyyy'))"

Get-VM -Name SRV-SIPSERVER | Get-NetworkAdapter | Set-NetworkAdapter -Connected:$false -Confirm:$false

GET-VM -Name $VMclone | Start-VM -Confirm:$False

##Desconnexion de vCenter

Disconnect-VIServer -Confirm:$false

##Para sentencia en caso de no tener conexion

break

}

}

0 Kudos
1 Reply
LucD
Leadership
Leadership

Did you already try the Send-MailMessage cmdlet?

Find an example in Re: send-mailmessage use in powercli scripts


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

0 Kudos