Exchange Exchange
A community dedicated to Exchange and related technology.

E-Mail Script

rated by 0 users
This post has 5 Replies | 2 Followers

John Brines Posted: 09-05-2008 8:42 AM

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 file
Get-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

  • | Post Points: 0
Top 10 Contributor
Points 3,290

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

  • | Post Points: 0

Hi Joel,

The e-mail address function works but the export csv doesn't. It comes in like below in Excel.

#TYPE Microsoft.PowerShell.Commands.Internal.Format.FormatStartData
ClassId2e4f51ef21dd47e99d3c952918aff9cd
033ecb2bc07a4d43b5ef94ed5a35d280
9e210fe47d09416682b841769c78b8a3
27c87ef9bbda4f709f6b4002fa4af63c
27c87ef9bbda4f709f6b4002fa4af63c
27c87ef9bbda4f709f6b4002fa4af63c
27c87ef9bbda4f709f6b4002fa4af63c
27c87ef9bbda4f709f6b4002fa4af63c

 

John.

Regards

John brines

  • | Post Points: 0
Top 10 Contributor
Points 3,290

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

- Joel

  • | Post Points: 0

Hi Joel,

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

John.

Regards

John brines

  • | Post Points: 0
Top 10 Contributor
Points 3,290

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?

 

 

- Joel

  • | Post Points: 0
Page 1 of 1 (6 items) | RSS
© 2003-2008 NamedPipes Consulting. All other company and product names are property of their owners.
Powered by Community Server (Non-Commercial Edition), by Telligent Systems