Tboz
2008-07-30 21:21:08 UTC
I'm new to this and have pieced together a script, but it is not working.
Can you help me figure out why I can't get this to email to me? I can get
the file to output but get a bunch of null errors
$FromAddress = ***@xxx.org
$ToAddress = ***@xxx.org
$MessageSubject = "Mailbox Size Report"
$MessageBody = "Attached is the current list of mailbox sizes."
$SendingServer = "xxx.org"
###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)
_______ERRORS_______________
New-Object : Exception calling ".ctor" with "4" argument(s): "The parameter
'from' cannot be an emp
ty string.
Parameter name: from"
At C:\emailstats.ps1:11 char:26
+ $SMTPMessage = New-Object <<<< System.Net.Mail.MailMessage $FromAddress,
$ToAddress,
You cannot call a method on a null-valued expression.
At C:\emailstats.ps1:14 char:29
+ $SMTPMessage.Attachments.Add( <<<< $Attachment)
Exception calling "Send" with "1" argument(s): "Value cannot be null.
Parameter name: message"
At C:\emailstats.ps1:18 char:17
+ $SMTPClient.Send( <<<< $SMTPMessage)
Can you help me figure out why I can't get this to email to me? I can get
the file to output but get a bunch of null errors
$FromAddress = ***@xxx.org
$ToAddress = ***@xxx.org
$MessageSubject = "Mailbox Size Report"
$MessageBody = "Attached is the current list of mailbox sizes."
$SendingServer = "xxx.org"
###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)
_______ERRORS_______________
New-Object : Exception calling ".ctor" with "4" argument(s): "The parameter
'from' cannot be an emp
ty string.
Parameter name: from"
At C:\emailstats.ps1:11 char:26
+ $SMTPMessage = New-Object <<<< System.Net.Mail.MailMessage $FromAddress,
$ToAddress,
You cannot call a method on a null-valued expression.
At C:\emailstats.ps1:14 char:29
+ $SMTPMessage.Attachments.Add( <<<< $Attachment)
Exception calling "Send" with "1" argument(s): "Value cannot be null.
Parameter name: message"
At C:\emailstats.ps1:18 char:17
+ $SMTPClient.Send( <<<< $SMTPMessage)