我正在使用一个 powershell 脚本,它将创建磁盘空间的 HTML 报告并将其作为电子邮件发送。不幸的是,我无法将脚本发送给多个电子邮件收件人。我正在使用的脚本可以在这里找到:
http://gallery.technet.microsoft.com/scriptcenter/6e935887-6b30-4654-b977-6f5d289f3a63
以下是脚本的相关部分...
$freeSpaceFileName = "FreeSpace.htm"
$serverlist = "C:\sl.txt"
$warning = 90
$critical = 75
New-Item -ItemType file $freeSpaceFileName -Force
Function sendEmail
{ param($from,$to,$subject,$smtphost,$htmlFileName)
$body = Get-Content $htmlFileName
$smtp= New-Object System.Net.Mail.SmtpClient $smtphost
$msg = New-Object System.Net.Mail.MailMessage $from, $to, $subject, $body
$msg.isBodyhtml = $true
$smtp.send($msg)
}
$date = ( get-date ).ToString('yyyy/MM/dd')
$recipients = "to1@email.com", "to2@email.com"
sendEmail from@email.mail $recipients "Disk Space Report - $Date" smtp.server $freeSpaceFileName
我收到以下错误
New-Object : Exception calling ".ctor" with "4" argument(s): "The specified string is not in the form required for an e
-mail address."
At E:\DiskSpaceReport.ps1:129 char:18
+ $msg = New-Object <<<< System.Net.Mail.MailMessage $from, $to, $subject, $body
+ CategoryInfo : InvalidOperation: (:) [New-Object], MethodInvocationException
+ FullyQualifiedErrorId : ConstructorInvokedThrowException,Microsoft.PowerShell.Commands.NewObjectCommand