Power Shell script to send a report.

Posted on 2009-04-29
Medium Priority
Last Modified: 2012-05-06
Howdy Everyone!

I asked a question a few days ago and got awsome help so was wondering if anyone would be able to help me with this problem I am having now. I wrote\copyed this script and input\edited my data in to it but I get nothing but errors. Could some one look this over and give some input?


P.S. Substitute USERNAME and SERVERNAME with real people \ server

Will Jones
###Send mailbox statistics script
###First, the administrator must change the mail message values in this section
$FromAddress = USERNAMEr@goodfellowbros.com
$ToAddress = USERNAME@goodfellowbros.com
$MessageSubject = "Mailbox Size Report"
$MessageBody = "Attached is the current list of mailbox sizes."
$SendingServer = "SERVERNAME.goodfellowbros.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")
###Send the message
$SMTPClient = New-Object System.Net.Mail.SMTPClient $SendingServer

Open in new window

Question by:Willie2232
1 Comment
LVL 12

Accepted Solution

Steven Wells earned 1000 total points
ID: 24264741
When you run it ensure that you don't have any extra line spaces, especailly at line
Get-MailboxStatistics | Sort-Object TotalItemSize -Descending | ft ' DisplayName,@{label="TotalItemSize(KB)";expression={$_.TotalItemSize.Value.ToKB()}}, ' ItemCount > mailboxes.txt

This must be one continous line with no carridge returns.

Also on the attachment line you can take out the .\ part and just make it "mailboxes.txt"

I had to make these changes to get this working myself.

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Want to know how to use Exchange Server Eseutil command? Go through this article as it gives you the know-how.
Here in this article, you will get a step by step guidance on how to restore an Exchange database to a recovery database. Get a brief on Recovery Database and how it can be used to restore Exchange database in this section!
In this video we show how to create an email address policy in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.:  First we need to log into the Exchange Admin Center. Navigate to the Mail Flow…
In this Micro Video tutorial you will learn the basics about Database Availability Groups and How to configure one using a live Exchange Server Environment. The video tutorial explains the basics of the Exchange server Database Availability grou…
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question