[英]Send email to multiple address in powershell
$PE is holds the email address of a user which is retrieved from AD user profile. $PE 保存从 AD 用户配置文件中检索到的用户的电子邮件地址。 I need to sent email to that user.
我需要向该用户发送电子邮件。 As it keeps on changing as per user profile I am finding it difficult to pass it into this email function.
由于它根据用户个人资料不断变化,我发现很难将其传递到此电子邮件功能中。
$PE=$(Get-aduser -filter {name -like $name} -properties mail).mail
Function abc($subject,$body,$PE)
{
$Htmlbody="____"
$toaddress = $PE
If (attachment -eq "")
{
Send-emailmessage -from "abc@xym.com" -bodyashtml -To $toaddress -body $htmlbody -subject $subject
}
}
I tried the above but I am getting an error for -To field and I don't see email address in $PE whereas $PE is holding the value before calling this function and inside the function it's empty.我尝试了上述操作,但是 -To 字段出现错误,并且我在 $PE 中没有看到电子邮件地址,而 $PE 在调用此函数之前保存了该值,并且在函数内部它是空的。
Here is the error :Cannot validate argument on parameter 'To' .the argument is null or empty .这是错误:无法验证参数 'To' 上的参数。该参数为 null 或 empty 。 Provide an argument that is not null or empty .
提供一个非 null 或 empty 的参数。 Then try again
然后再试一次
(1) Variables defined in a function are applicable only inside that function unless you scope otherwise - see Powershell documentaiton about "Scoping" for details (1) 函数中定义的变量仅适用于该函数内部,除非您另有范围 - 有关详细信息,请参阅 Powershell 文档“范围”
(2) Create the function then PASS the parameters to the function. (2) 创建函数,然后将参数传递给函数。 It's easier to understand this if you use the "longhand" way of passing parameters
如果您使用传递参数的“普通”方式,则更容易理解这一点
$PE=$(Get-aduser -filter {name -like $name} -properties mail).mail
Function abc {
Param(
$subject,
$body,
$toaddress)
Send-emailmessage -from "abc@xym.com" -bodyashtml -To $toaddress -body $body -subject $subject
}
abc -subject "MySubject" -body "____" -toaddress $PE
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.