Jazo
 New Member Posts:58

 |
| 09 Dec 2008 12:31 AM |
|
Hi
I could use some help here. I would like to have a script that pulls out MailboxStatistics for a couple of Mailboxservers and mailed to me with the day and month.
my script:
$VarDay = (Get-Date).day $VarMonth = (Get-Date).month Get-MailboxStatistics -server |select DisplayName,TotalItemSize,StorageLimitStatus, Database| sort-object TotalItemSize -Descending
I'm pretty new at this and would appreciate any help here. |
|
|
|
|
Dan Ball
 Basic Member Posts:154

 |
| 09 Dec 2008 03:54 AM |
|
Here is the one I use each night, maybe you can modify it to what you need:
$Day = (Get-Date).day $Month = (Get-Date).month $Year = (Get-Date).Year $mailbox1 = "Mailbox Report for $Day/$Month/$Year`n" $mailbox2 = Get-MailboxStatistics | Sort-Object TotalItemSize -Descending | ft DisplayName,@{label="TotalItemSize(MB)";expression={$_.TotalItemSize.Value.ToMB()}},ItemCount | Out-String $messagesubject = "Daily Mailbox Usage Report" $mailboxfinal = $mailbox1 + $mailbox2 $SmtpClient = new-object system.net.mail.smtpClient $MailMessage = New-Object system.net.mail.mailmessage $SmtpClient.Host = "localhost" $mailmessage.from = "fromaddress@domain.com" $mailmessage.To.add(addressee1@domain.com) $mailmessage.To.add(addressee2@domain.com) $mailmessage.Subject = $messagesubject $mailmessage.Body = $mailboxfinal $smtpclient.Send($mailmessage) |
|
|
|
|
Dan Ball
 Basic Member Posts:154

 |
| 09 Dec 2008 04:56 AM |
|
I forgot I had recently changed it to add users that are in warning/prohibit send state... Here are the changed lines:
$mailbox1 = "Mailbox Report for $Day/$Month/$Year`n" $mailbox2 = Get-MailBoxStatistics | where {"IssueWarning","ProhibitSend","MailboxDisabled" -contains $_.StorageLimitStatus} | sort-object storagelimitstatus -Descending | ft DisplayName, StorageLimitStatus, LastLogonTime | Out-String $mailbox3 = Get-MailboxStatistics | Sort-Object TotalItemSize -Descending | ft DisplayName,@{label="TotalItemSize(MB)";expression={$_.TotalItemSize.Value.ToMB()}},ItemCount | Out-String $messagesubject = "Daily Mailbox Usage Report" $mailboxfinal = $mailbox1 + $mailbox2 + $mailbox3
|
|
|
|
|
Jazo
 New Member Posts:58

 |
| 09 Dec 2008 06:09 AM |
|
Thank you very much, this was great! Got me up and running. |
|
|
|
|
Jazo
 New Member Posts:58

 |
| 08 Feb 2010 04:07 AM |
|
I would also like to add the users (displayName) Manager as well...how do I need to go about this?
Thanks... |
|
|
|
|
SACIT
 New Member Posts:2

 |
| 22 Feb 2010 05:02 PM |
|
Not sure what I'm doing wrong but I'm executing this script from the exchange server.
PS C:\scripts> C:\scripts\EmailStats.ps1 Missing ')' in method call. At C:\scripts\EmailStats.ps1:15 char:21 + $mailmessage.To.add( <<<< First.last@domain.com) + CategoryInfo : ParserError: (CloseParenToken:TokenId) [], ParentContainsErrorRecordException + FullyQualifiedErrorId : MissingEndParenthesisInMethodCall Below is the full script: $Day = (Get-Date).day $Month = (Get-Date).month $Year = (Get-Date).Year $mailbox1 = "Mailbox Report for $Day/$Month/$Year`n" $mailbox2 = Get-MailBoxStatistics | where {"IssueWarning","ProhibitSend","MailboxDisabled" -contains $_.StorageLimitStatus} | sort-object storagelimitstatus -Descending | ft DisplayName, StorageLimitStatus, LastLogonTime | Out-String $mailbox3 = Get-MailboxStatistics | Sort-Object TotalItemSize -Descending | ft DisplayName,@{label="TotalItemSize(MB)";expression={$_.TotalItemSize.Value.ToMB()}},ItemCount | Out-String $messagesubject = "Daily Mailbox Usage Report" $mailboxfinal = $mailbox1 + $mailbox2 + $mailbox3 $messagesubject = "Daily Mailbox Usage Report" $mailboxfinal = $mailbox1 + $mailbox2 $SmtpClient = new-object system.net.mail.smtpClient $MailMessage = New-Object system.net.mail.mailmessage $SmtpClient.Host = "mailserver.domain.com" $mailmessage.from = "reports@domain" $mailmessage.To.add(First.last@domain.com) $mailmessage.Subject = $messagesubject $mailmessage.Body = $mailboxfinal $smtpclient.Send($mailmessage) |
|
|
|
|
Karl Mitschke
 Basic Member Posts:457

 |
|
SACIT
 New Member Posts:2

 |
| 23 Feb 2010 07:49 AM |
|
worked. Thanks! |
|
|
|
|
Jazo
 New Member Posts:58

 |
| 24 Feb 2010 04:12 AM |
|
Karl...would you know how to add a users Manager too....to this report..??? |
|
|
|
|
Jazo
 New Member Posts:58

 |
| 24 Feb 2010 05:04 AM |
|
Was thinking about using Get-User and foreach objitem ...but not sure how to put it inn and where...any help..please... |
|
|
|
|
Dan Ball
 Basic Member Posts:154

 |
| 02 Mar 2010 09:27 AM |
|
Not sure exactly what you are looking for, but I wrote the script with a mind to expand the TO addressees easily... Just duplicate this line as many times as you want to add multiple e-mail addresses: $mailmessage.To.add("First.last@domain.com")
|
|
|
|
|
Ken Foster
 New Member Posts:2

 |
| 15 Mar 2010 10:49 AM |
|
I am running this script saved as getmailstats.ps1
$Day = (Get-Date).day $Month = (Get-Date).month $Year = (Get-Date).Year $mailbox1 = "Mailbox Report for $Day/$Month/$Year`n" $mailbox2 = Get-MailBoxStatistics | where {"IssueWarning","ProhibitSend","MailboxDisabled" -contains $_.StorageLimitStatus} | sort-object storagelimitstatus -Descending | ft DisplayName, StorageLimitStatus, LastLogonTime | Out-String $mailbox3 = Get-MailboxStatistics | Sort-Object TotalItemSize -Descending | ft DisplayName,@{label="TotalItemSize(MB)";expression={$_.TotalItemSize.Value.ToMB()}},ItemCount | Out-String $messagesubject = "Daily Mailbox Usage Report" $mailboxfinal = $mailbox1 + $mailbox2 + $mailbox3 $messagesubject = "Daily Mailbox Usage Report" $mailboxfinal = $mailbox1 + $mailbox2 $SmtpClient = new-object system.net.mail.smtpClient $MailMessage = New-Object system.net.mail.mailmessage $SmtpClient.Host = "localhost" $mailmessage.from = "reports@root.local" $mailmessage.To.add("First.last@root.local") $mailmessage.Subject = $messagesubject $mailmessage.Body = $mailboxfinal $smtpclient.Send($mailmessage)
When i run it i get this error
$smtpclient.Send($mailmessage)\Windows\System32>getmailstats.ps1 Exception calling "Send" with "1" argument(s): "Service not available, closing transmission channel. The server response was: 4.3.2 Service not available, closing transmission channel" At C:/Windows\system32\getmailstats.ps1:18 char:17 + $smtpclient.Send( <<<< $mailmessage)
Anyone have any suggestion on what i am doing wrong Thank you Ken
|
|
|
|
|
Karl Mitschke
 Basic Member Posts:457

 |
|
Ken Foster
 New Member Posts:2

 |
| 18 Mar 2010 05:33 AM |
|
I changed it from localhost to the mail server FQDN and get the same error |
|
|
|
|
Karl Mitschke
 Basic Member Posts:457

 |
|
mallikarjun shetty
 New Member Posts:6

 |
| 25 Mar 2010 11:29 PM |
|
Hi, I am trying to get the mailbox statistics of all the users in exhange server 2007 remotely using following script but it is giving error, please help me if anything is missed out in the script.
Active Directory server vanguard.itsmenabler.co.in is not available. Error mess age: The supplied credential is invalid. + CategoryInfo : NotSpecified: (0:Int32) [Get-MailboxServer], ADO perationException + FullyQualifiedErrorId : EA7AFE01,Microsoft.Exchange.Management.SystemCon figurationTasks.GetMailboxServer
script takes hostname,username and password of exchange server function Get-PassCred { $pass = ConvertTo-SecureString -force -AsPlainText -string $password $return = New-Object System.Management.Automation.PSCredential -ArgumentList $username ,$pass $return }
function Get-Connection { $return = new-pssession -ComputerName $hostname -credential $cred $return } function Get-Data { #invoke-command -ComputerName $hostname -credential $cred -scriptblock {Add-PSSnapin Microsoft.Exchange.Management.PowerShell.Admin} invoke-command -session $mysession -scriptblock {Add-PSSnapin Microsoft.Exchange.Management.PowerShell.Admin;get-wmiobject win32_computersystem;get-queue ;get-mailbox;Remove-PSSnapin Microsoft.Exchange.Management.PowerShell.Admin} # invoke-command -ComputerName $hostname -credential $cred -scriptblock {Remove-PSSnapin Microsoft.Exchange.Management.PowerShell.Admin} }
function Disconnect-Session { remove-pssession -session (get-pssession) } $hostname = $args[0] $username = $args[1] $password = $args[2] $cred = Get-PassCred #$cred | Out-Host $mysession = Get-Connection Get-Data #$error Disconnect-Session # Set-User Administrator -RemotePowerShellEnabled $true; # | Export-Clixml e:\exchange.xml -noclobber |
|
|
|
|
Dan Ball
 Basic Member Posts:154

 |
| 03 May 2010 05:51 AM |
|
Sorry I didn't see this earlier, didn't have notifications turned on for this thread. Anyways, the $SmtpClient.Host = "localhost" line can be changed to a FQDN ("server.domain.com") with no problem, I use it all the time like that. You will need to make sure you have port 25 open on the computer you are sending from though, and the SMTP server you are attempting to use will also need to be configured to accept connections from the computer you are sending from. Also, if you are using an Exchange Server, and the recipients of the e-mails are hosted on the same server as you are using for an SMTP server, then the relaying issue will not affect you. If you are attempting to send to a different e-mail address though, you will need to configure your server to allow relaying.
|
|
|
|
|
Jazo
 New Member Posts:58

 |
| 31 May 2010 12:54 AM |
|
Hi, I'm using this script: $Day = (Get-Date).day $Month = (Get-Date).month $Year = (Get-Date).Year $mailbox1 = "Mailbox Report for $Day/$Month/$Year`n" $mailbox2 = Get-MailboxStatistics -server ServerName | Sort-Object TotalItemSize -Descending | ft DisplayName,@{label="TotalItemSize(MB)";expression={$_.TotalItemSize.Value.ToMB()}},ItemCount | out-string $messagesubject = "Mailbox Usage Report" $mailboxfinal = $mailbox1 + $mailbox2 $SmtpClient = new-object system.net.mail.smtpClient $MailMessage = New-Object system.net.mail.mailmessage $SmtpClient.Host = "smtp.domain.com" $mailmessage.from = "address@domain.com" $mailmessage.To.add("address@domain.com") $mailmessage.Subject = $messagesubject $MailMessage.IsBodyHtml = $false $mailmessage.Body = $mailboxfinal $smtpclient.Send($mailmessage) The issue is, that I would like to add one more value in the report. How can get the script to read the user and query: Get-qaduser "user" and display the Manager in the report?
|
|
|
|
|
shireesh
 New Member Posts:1

 |
| 20 Jul 2010 10:45 PM |
|
Works fine for me.It would be great if it carries out a way based on storage quota percentage value the user is sent a mail along with his manager as a gentle reminder to trim their mailbox size. http://www.messageops.com/blog/inde...cript.htmlJazo Did you find a way out to pull manager details in the report |
|
|
|
|
Jazo
 New Member Posts:58

 |
| 20 Jul 2010 11:11 PM |
|
No shireesh, not yet. Still working on that one. Any suggestions? |
|
|
|
|
Dan Ball
 Basic Member Posts:154

 |
| 21 Jul 2010 03:22 AM |
|
It can be done, it will just require a bit more complex of a script. Here is the way I would approach it: 1. I would use the above script to create the initial information, mostly leaving it as-is. 2. In the script I would also use the information generated to create an array of information, the username if nothing else. 3. At the end of the script, I would use a foreach loop to go through the array and get the detailed information for each username. 4. During that loop, I would have it create indvidualized e-mails, listing all the important information.
|
|
|
|
|