Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/email/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Email PowerShell向其他脚本中的地址列表发送电子邮件_Email_Powershell_Powershell 2.0_Ping - Fatal编程技术网

Email PowerShell向其他脚本中的地址列表发送电子邮件

Email PowerShell向其他脚本中的地址列表发送电子邮件,email,powershell,powershell-2.0,ping,Email,Powershell,Powershell 2.0,Ping,我正在尝试创建一个PowerShell脚本,该脚本将向人员列表发送电子邮件,但电子邮件呼叫已嵌入到ping脚本中。这适用于仅具有PowerShell v2.0的系统 Computers.txt包含要ping的计算机列表,失败时将发送电子邮件 这是我正在尝试修改的现有脚本: Get-Content -path "E:\Computers.txt" | ForEach-Object { if (-not (Test-Connection -ComputerName $_ -Delay 2 -Quie

我正在尝试创建一个PowerShell脚本,该脚本将向人员列表发送电子邮件,但电子邮件呼叫已嵌入到ping脚本中。这适用于仅具有PowerShell v2.0的系统

Computers.txt包含要ping的计算机列表,失败时将发送电子邮件

这是我正在尝试修改的现有脚本:

Get-Content -path "E:\Computers.txt" | ForEach-Object {
if (-not (Test-Connection -ComputerName $_ -Delay 2 -Quiet)) {
    Send-MailMessage -To "email address" -Subject "$_ is Unreachable" -Body "$_ is unreachable by ping. Next check is in 5 minutes" -SmtpServer "server address" -From "another email address"  
    } 
}
我知道我可以使用Get-Content-path“E:\From_Email.txt”和Get-Content-path“E:\To_Email.txt”来调用电子邮件地址列表,但我不确定如何在现有命令中执行此操作。我在网上查找过,但没有找到如何在PowerShell中嵌套调用其他文本文件以获取脚本


我是否需要提前调用这些文件并将它们设置为一个被调用的变量?任何帮助都将不胜感激。谢谢。

假设您在“E:\To\u email.txt”的每一行上都有一个电子邮件地址,下面的代码应该可以工作

$emails = (Get-Content "E:\To_Email.txt") -join ";"
Get-Content -path "E:\Computers.txt" | ForEach-Object {
if (-not (Test-Connection -ComputerName $_ -Delay 2 -Quiet)) {
  Send-MailMessage -To $emails -Subject "$_ is Unreachable" -Body "$_ is unreachable by ping. Next check is in 5 minutes" -SmtpServer "server address" -From "another email address"  
  }
}
额外的第一行作为一个数组读入电子邮件列表文件的所有行,然后用分号将其连接起来,我认为这就是电子邮件地址的分隔方式。不过值得一查

“E:\To\u Email.txt”的内容示例


我使用了这个脚本,但在使用-join“;”时,当电子邮件试图发送时,我最终得到了标题错误。相反,我省略了整个-join“;”语句,它工作得非常好。非常感谢。
person.one@yourdomain.whatever
person.two@yourdomain.whatever
person.three@yourdomain.whatever
person.four@yourdomain.whatever