【发布时间】:2020-08-17 04:55:59
【问题描述】:
我们创建了一个工件 "Clone a Git Repo" - 从 git hub 克隆 PS1 脚本 “运行 Powershell”运行 PS1 脚本。 这些工件与公式相关联。
在创建新 VM 时,会应用公式来运行 PS1 脚本。 运行公式后,尝试使用以下 powershell ps1 脚本发送邮件。
PS1 脚本
...
...
##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
我厌倦了这样做,但脚本无法发送消息可能是因为$env:UserName 无效。如何获取 VM 用户名作为 PS1 的参数,以便附加 gmail.com 并发送?
【问题讨论】:
标签: azure azure-vm azure-devtest-labs