We help IT Professionals succeed at work.
Get Started

Powershell Script: Need help executing

pzozulka asked
Last Modified: 2012-05-07
I read the article below, and decided to use the script provided within. According to the article the script should email me a list of all the users' mailbox size.

However, when I try to run this script via Powershell it does not work. Any ideas why and what I can do to resolve this?

###Send mailbox statistics script
###First, the administrator must change the mail message values in this section
$FromAddress = it@domain.com
$ToAddress = pavelz@domain.com
$MessageSubject = "Mailbox Size Report"
$MessageBody = "Attached is the current list of mailbox sizes."
$SendingServer = "martini.bcr.local"
###Now get the stats and store in a text file
Get-MailboxStatistics | Sort-Object TotalItemSize -Descending | ft
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

Watch Question
PowerShell Developer
Top Expert 2010
This problem has been solved!
Unlock 1 Answer and 9 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE