• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 564
  • Last Modified:

Power Shell script to send a report.

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?

Thanks!

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")
$SMTPMessage.Attachments.Add($Attachment)
 
###Send the message
$SMTPClient = New-Object System.Net.Mail.SMTPClient $SendingServer
$SMTPClient.Send($SMTPMessage)

Open in new window

0
Willie2232
Asked:
Willie2232
1 Solution
 
Steven WellsSystems AdministratorCommented:
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.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

Tackle projects and never again get stuck behind a technical roadblock.
Join Now