我需要一点帮助,我的脚本。如果我只使用一个电子邮件地址,我有这个工作。我需要添加一个8个电子邮件地址列表来扫描。我如何修改这个为所有8个用户发送1封电子邮件?脚本来计算多个用户的电子邮件数
我已经看到了一个脚本,它能够将html文件显示在一个漂亮的表格中,但是这些脚本是针对所有交换用户运行的,我只需要一组8个用户。
Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010
#Powershell blah blah blah
$nl = [Environment]::NewLine
#Mailbox to gather stats on
$mailboxs=$mailbox= '[email protected]','[email protected]'
#Get todays
$startDate=Get-Date
$endDate=Get-Date
#Subtract 1 day from todays date (report ending day) and 1 day from todays date (report starting day)
$startDateFormatted=$startDate.AddDays(-1).ToShortDateString()
$endDateFormatted=$endDate.AddDays(-1).ToShortDateString()
foreach ($mailbox in $mailboxs)
{
# Sent e-mails
$sendCount = Get-TransportService | Get-MessageTrackingLog -Start "$startDateFormatted 00:00:00" -End "$endDateFormatted 23:59:59" -Sender $mailbox -resultsize unlimited | select-object -unique MessageId
# Received e-mails - This works but not on generic accounts
$receiveCount = Get-TransportService | Get-MessageTrackingLog -Start "$startDateFormatted 00:00:00" -End "$endDateFormatted 23:59:59" -Recipients $mailbox -resultsize unlimited | select-object -unique MessageId
$sendCountString = $sendCount.count
$receiveCountString = $receiveCount.count
}
$Output =
$Mailbox |
foreach {
$ResultHash =
@{
Address = $_
Sent = $Sendcountstring
Received = $Receivecountstring
}
New-Object -TypeName PSObject -Property $ResultHash |
Select Address,Sent,Received
}
#Who to send the e-mail report to.
#Multiple e-mail addresses should be in this format "<[email protected]>, <[email protected]>"
$MailParams = @{
From = "[email protected]"
To = "[email protected]"
subject = "Daily e-mail report for ISS for $startDateFormatted"
BodyAsHTML = $true
smtpServer = "mail.domain.com"
}
$header =
@"
"Mailbox Stats
Report date range: $startDateFormatted 00:00:00 - $endDateFormatted 23:59:59
"@
$body = $Output | ConvertTo-Html -As Table -Head $header | out-string
Send-MailMessage @MailParams -Body $body
这是我现在运行它的错误消息。 Send-MailMessage:无法将'System.Object []'转换为参数'Body'所需的类型'System.String'。不支持指定的 方法。 在C:\ Users \ dbeavin \ Desktop \ ISSTest.ps1:70 char:36 + Send-MailMessage @MailParams -Body $ body + ~~~~~ + CategoryInfo:InvalidArgument:(:) [Send-MailMessage ],ParameterBindingException + FullyQualifiedErrorId:CannotConvertArgument,Microsoft.PowerShell.Commands.SendMailMessage – 2015-04-01 01:05:49
因为需要加载Exchange cmdlet,所以我还必须在顶部添加Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010。我将此作为计划任务使用,因此我需要将其添加进来。 – 2015-04-01 01:06:52
通过$ body的out-string添加了一个管道。这应该可以解决这个错误。您不一定必须加载捕获才能拥有Exchange cmdlet。我通常只连接到Exchange服务器并使用隐式远程处理,因此我不必在服务器上安装和更新Exchange管理工具。 – mjolinor 2015-04-01 01:29:42