Hi Guys,
I am using an e-mail script from a BLOG that sends an e-mail with some mailbox stats. The script works fine but I want to be able to have more than one recipient on it. I was wonder if someone could help me? If possible if we can get a CC Address?
Also how can I have it in HTML format or CSV format?
###Send mailbox statistics script
###First, the administrator must change the mail message values in this section$FromAddress = "mailboxstats@company.com"$ToAddress = "john.brines@company.com"$MessageSubject = "Mailbox Size Report"$MessageBody = "Attached is the current list of mailbox sizes."$SendingServer = "smtp.company.com"
###Now get the stats and store in a text fileGet-MailboxStatistics | Sort-Object TotalItemSize -Descending | ft DisplayName,@{label="TotalItemSize(KB)";expression={$_.TotalItemSize.Value.ToKB()}}, ItemCount > mailboxes.txt
###Create the mail message and add the statistics text file as an attachment$SMTPMessage = New-Object System.Net.Mail.MailMessage $FromAddress, $ToAddress, $MessageSubject, $MessageBody$Attachment = New-Object Net.Mail.Attachment("./mailboxes.txt")$SMTPMessage.Attachments.Add($Attachment)
###Send the message$SMTPClient = New-Object System.Net.Mail.SMTPClient $SendingServer$SMTPClient.Send($SMTPMessage)
Regards
John brines
You should be able to use export-csv to get the mailboxes.txt to be in a csv format.
Get-MailboxStatistics | Sort-Object TotalItemSize -Descending | ft select-object DisplayName,@{label name="TotalItemSize(KB)";expression={$_.TotalItemSize.Value.ToKB()}}, ItemCount | Export-CSV mailboxes.csv
I haven't tried this but you should be able to add multiple email addresses just by putting a comma (and no spaces) between them. As an example you'd change the line to be:
$ToAddress = "john.brines@company.com,joel.stidley@company.com"
- Joel
Hi Joel,
The e-mail address function works but the export csv doesn't. It comes in like below in Excel.
John.
Sorry it took me a few days to have an opportunity to sit in front of an Exchange server, but its a simple change out of format-table to select-object (and a change from label to name). Format-table is meant to format the data for display on the screen, not for exporting so select-object should be used instead.
Get-MailboxStatistics | Sort-Object TotalItemSize -Descending | select-object DisplayName,@{Name="TotalItemSize(KB)";Expression={$_.TotalItemSize.Value.ToKB()}},ItemCount | Export-CSV mailboxes.csv
Thanks for that.
Apart from the book "Windows Powershell for Exchange Server 2007 SP1" can you recommend some good material for learning Windows Powershell especially for a novice?
Cheers
Is there any book besides Windows PowerShell for Exchange Server 2007 SP1? :)
I've read Professional Windows PowerShell and I really enjoyed it.
Anyone else in the forums have suggestions?