We have a artifacts created "Clone a Git Repo" - Clones the PS1 script from git hub "Run Powershell" run the PS1 script. These artifact is linked to Formulae.
On creating a new VM, the Formulae is applied to run which runs the PS1 script. Tried to a use the below powershell ps1 script to send mail once the formulae is run.
PS1 script
...
...
##Send mail to the User email
$ipV4 = Test-Connection -ComputerName (hostname) -Count 1 | Select -ExpandProperty IPV4Address
$emailId = $env:UserName+"@gmail.com"
$body = "<html>
<body>
Hi $emailId, </br>
</br>
Your VM $ipV4 is ready to access. <br/>
Thanks,</br>
Digital Engagement Team
</body>
</html>"
Send-MailMessage -To $emailId -from *** -Subject "Azure VM $ipV4 is Ready" -SmtpServer ****** -port 25 -Body $body -BodyAsHtml
I tired to do this but the script is failing to send message may be becauseof $env:UserName
is not valid. How can I get the VM username as parameter to PS1 so that I can append gmail.com and send?