Add info in my Script
Hello,I am using the below script to get mailbox statistic (exch 2007).I would need to add in that script the total number of Exchange mailbox (So I thought about that command --> Get-MailboxStatistics | Measure-Object )It is a simple info that I need to add in the script but cannot manage to find where and how to implemant the command.Can you please help me out with that ?? Below my script:function SendMail($Recipient){ $SmtpClient = new-object system.net.mail.smtpClient $MailMessage = New-Object system.net.mail.mailmessage $SmtpClient.Host = "Server01.company.intra" $mailmessage.from = "administrator@company.com" $mailmessage.To.add("$Recipient") $mailmessage.Subject = "[company] Mailbox Statistics - $date" $mailmessage.IsBodyHTML = $true $mailmessage.Body = $body #add attachment $mailattachment = new-object System.Net.Mail.Attachment($attachment) $mailmessage.attachments.add($mailattachment) $smtpclient.Send($mailmessage)} $date = $(get-date).GetDateTimeFormats()[6] $a = "<style>"$a = $a + "BODY{background-color:#FFFFFF;}"$a = $a + "TABLE{border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;}"$a = $a + "TH{border-width: 1px;padding: 0px;border-style: solid;border-color: black;background-color:#FFFF99}"$a = $a + "TD{border-width: 1px;padding: 0px;border-style: solid;border-color: black;background-color:#FFFF99}"$a = $a + "</style>" Get-MailboxStatistics | Sort-Object TotalItemSize -Descending | ConvertTo-HTML -head $a -property DisplayName, @{l="TotalItemSize(KB)";expression={$_.TotalItemSize.Value.ToKB()}},ItemCount | Out-File c:\scripts\mailboxes.htm $Recipient = "graig@company.com"$body = gc "c:\scripts\mailboxes.htm"$attachment = "c:\scripts\mailboxes.htm"SendMail($Recipient)
February 8th, 2010 4:10pm

In this case the easiest way to get a count of the number of mailboxes might be $mbxcount = (gc c:\scripts\mailboxes.htm).count -14$body += "Total =mailbox count is $($mbxcount)."
Free Windows Admin Tool Kit Click here and download it now
February 8th, 2010 4:47pm

Thanks Mjolinor,Can you please tell me where I should insert those 2 lines in the script??$mbxcount = (gc c:\scripts\mailboxes.htm).count -14$body += "Total =mailbox count is $($mbxcount)."
February 8th, 2010 6:09pm

function SendMail($Recipient){ $SmtpClient = new-object system.net.mail.smtpClient $MailMessage = New-Object system.net.mail.mailmessage $SmtpClient.Host = "Server01.company.intra" $mailmessage.from = "administrator@company.com" $mailmessage.To.add("$Recipient") $mailmessage.Subject = "[company] Mailbox Statistics - $date" $mailmessage.IsBodyHTML = $true $mailmessage.Body = $body #add attachment $mailattachment = new-object System.Net.Mail.Attachment($attachment) $mailmessage.attachments.add($mailattachment) $smtpclient.Send($mailmessage)} $date = $(get-date).GetDateTimeFormats()[6] $a = "<style>"$a = $a + "BODY{background-color:#FFFFFF;}"$a = $a + "TABLE{border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;}"$a = $a + "TH{border-width: 1px;padding: 0px;border-style: solid;border-color: black;background-color:#FFFF99}"$a = $a + "TD{border-width: 1px;padding: 0px;border-style: solid;border-color: black;background-color:#FFFF99}"$a = $a + "</style>" Get-MailboxStatistics | Sort-Object TotalItemSize -Descending | ConvertTo-HTML -head $a -property DisplayName, @{l="TotalItemSize(KB)";expression={$_.TotalItemSize.Value.ToKB()}},ItemCount | Out-File c:\scripts\mailboxes.htm $mbxcount = (gc c:\scripts\mailboxes.htm).count -14 $Recipient = "graig@company.com"$body = gc "c:\scripts\mailboxes.htm"$body += "Total =mailbox count is $($mbxcount)."$attachment = "c:\scripts\mailboxes.htm"SendMail($Recipient)Note: using the line count of the htm file to retrieve the number of mailboxes won't be reliable if you add more formatting lines. A more reliable method might be to tee the output off to get a count from: function SendMail($Recipient){ $SmtpClient = new-object system.net.mail.smtpClient $MailMessage = New-Object system.net.mail.mailmessage $SmtpClient.Host = "Server01.company.intra" $mailmessage.from = "administrator@company.com" $mailmessage.To.add("$Recipient") $mailmessage.Subject = "[company] Mailbox Statistics - $date" $mailmessage.IsBodyHTML = $true $mailmessage.Body = $body #add attachment $mailattachment = new-object System.Net.Mail.Attachment($attachment) $mailmessage.attachments.add($mailattachment) $smtpclient.Send($mailmessage)} $date = $(get-date).GetDateTimeFormats()[6] $a = "<style>"$a = $a + "BODY{background-color:#FFFFFF;}"$a = $a + "TABLE{border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;}"$a = $a + "TH{border-width: 1px;padding: 0px;border-style: solid;border-color: black;background-color:#FFFF99}"$a = $a + "TD{border-width: 1px;padding: 0px;border-style: solid;border-color: black;background-color:#FFFF99}"$a = $a + "</style>" Get-MailboxStatistics | Sort-Object TotalItemSize -Descending | tee-object -variable stats | ConvertTo-HTML -head $a -property DisplayName, @{l="TotalItemSize(KB)";expression={$_.TotalItemSize.Value.ToKB()}},ItemCount | Out-File c:\scripts\mailboxes.htm$mbxcount = $stats.count $Recipient = "graig@company.com"$body = gc "c:\scripts\mailboxes.htm"$body += "Total =mailbox count is $($mbxcount)."$attachment = "c:\scripts\mailboxes.htm"SendMail($Recipient)
Free Windows Admin Tool Kit Click here and download it now
February 8th, 2010 6:28pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics