header
header Register : : Login header
header
divider
menuleft
menuright
submenu
left

We have a new sponsor!  Introducting Pragma Systems.  See the home page for details.

Get-MailboxStatistics -server script
Last Post 21 Jul 2010 12:22 PM by DanBall. 20 Replies.
Printer Friendly
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages
JazoUser is Offline
New Member
New Member
Posts:61
Avatar

--
09 Dec 2008 09: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.

DanBallUser is Offline
Basic Member
Basic Member
Posts:150
Avatar

--
09 Dec 2008 12:54 PM  

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)

DanBallUser is Offline
Basic Member
Basic Member
Posts:150
Avatar

--
09 Dec 2008 01:56 PM  
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

JazoUser is Offline
New Member
New Member
Posts:61
Avatar

--
09 Dec 2008 03:09 PM  
Thank you very much, this was great! Got me up and running.
JazoUser is Offline
New Member
New Member
Posts:61
Avatar

--
08 Feb 2010 01:07 PM  
I would also like to add the users (displayName) Manager as well...how do I need to go about this?

Thanks...
sacitUser is Offline
New Member
New Member
Posts:2
Avatar

--
23 Feb 2010 02:02 AM  
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)
KarlMitschkeUser is Offline
Basic Member
Basic Member
Posts:330
Avatar

--
23 Feb 2010 03:09 PM  
Hello;

Change line 15 to
$mailmessage.To.add("First.last@domain.com")

Karl
http://unlockpowershell.wordpress.com
-join("6B61726C6D69747363686B65406D742E6E6574"-split"(?<=\G.{2})",19|%{[char][int]"0x$_"})
sacitUser is Offline
New Member
New Member
Posts:2
Avatar

--
23 Feb 2010 04:49 PM  
worked. Thanks!
JazoUser is Offline
New Member
New Member
Posts:61
Avatar

--
24 Feb 2010 01:12 PM  
Karl...would you know how to add a users Manager too....to this report..???
JazoUser is Offline
New Member
New Member
Posts:61
Avatar

--
24 Feb 2010 02:04 PM  
Was thinking about using Get-User and foreach objitem ...but not sure how to put it inn and where...any help..please...
DanBallUser is Offline
Basic Member
Basic Member
Posts:150
Avatar

--
02 Mar 2010 06:27 PM  
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")
kenrfosterUser is Offline
New Member
New Member
Posts:2
Avatar

--
15 Mar 2010 07:49 PM  

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

KarlMitschkeUser is Offline
Basic Member
Basic Member
Posts:330
Avatar

--
17 Mar 2010 05:57 PM  
Is localhost actually a mail server?
http://unlockpowershell.wordpress.com
-join("6B61726C6D69747363686B65406D742E6E6574"-split"(?<=\G.{2})",19|%{[char][int]"0x$_"})
kenrfosterUser is Offline
New Member
New Member
Posts:2
Avatar

--
18 Mar 2010 02:33 PM  
I changed it from localhost to the mail server FQDN and get the same error
KarlMitschkeUser is Offline
Basic Member
Basic Member
Posts:330
Avatar

--
18 Mar 2010 02:59 PM  
Can you telnet to the smtp server and send mail?

See an example here:
http://www.cs.cf.ac.uk/Dave/PERL/node175.html

Is your SMTP server also your Exchange server? Is it setup to allow relaying?

Karl
http://unlockpowershell.wordpress.com
-join("6B61726C6D69747363686B65406D742E6E6574"-split"(?<=\G.{2})",19|%{[char][int]"0x$_"})
mallikarjunUser is Offline
New Member
New Member
Posts:6
Avatar

--
26 Mar 2010 08:29 AM  
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
DanBallUser is Offline
Basic Member
Basic Member
Posts:150
Avatar

--
03 May 2010 02:51 PM  
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.

JazoUser is Offline
New Member
New Member
Posts:61
Avatar

--
31 May 2010 09: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?
shireeshUser is Offline
New Member
New Member
Posts:1
Avatar

--
21 Jul 2010 07:45 AM  
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/index.php?/archives/31-Exchange-Online-Mailbox-Size-Warning-Notification-Script.html


Jazo

Did you find a way out to pull manager details in the report
JazoUser is Offline
New Member
New Member
Posts:61
Avatar

--
21 Jul 2010 08:11 AM  
No shireesh, not yet. Still working on that one. Any suggestions?
DanBallUser is Offline
Basic Member
Basic Member
Posts:150
Avatar

--
21 Jul 2010 12:22 PM  
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.
You are not authorized to post a reply.

Active Forums 4.1
right
   
footer Sponsored by Quest Software • SAPIEN Technologies • Compellent • Microsoft Windows Server 2008 footer
footer