我想用PowerShell將Send-MailMessage
分配給多個用戶。 這工作:Send-MailMessage多個解析變量
Send-MailMessage -To "[email protected]", "[email protected]" -Subject "TEST BASE INCIDENT SCRIPT" -Body "TEST" -SmtpServer $emailSMTP -BodyAsHtml -Credential $emailCredential -Encoding $emailEncoding
我有一個變量$email
我有構造是這樣的:
$email = ''
$c = 0
foreach ($currentValue in $value) {
$id = $currentValue.LookupId
$spUserManager = $spweb.AllUsers.GetByID($id)
if ($c -gt 0) {
$email += ","+($spUserManager.Name + " <" + $spUserManager.Email + ">")
} else {
$email += ($spUserManager.Name + " <" + $spUserManager.Email + ">")
}
$c++
}
但是,當我跟我的變量$email
更換-To
,忽略了最低的工作。 (沒有錯誤,只需發送給$email
中的第一位用戶)。
Send-MailMessage -To $email -Subject "TEST BASE INCIDENT SCRIPT" -Body "TEST" -SmtpServer $emailSMTP -BodyAsHtml -Credential $emailCredential -Encoding $emailEncoding