我需要一點幫助,我的腳本。如果我只使用一個電子郵件地址,我有這個工作。我需要添加一個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