Solved

How to script the exchagne quota process seperately?

Posted on 2014-11-25
14
131 Views
Last Modified: 2014-12-03
We are using exchange 2010 on our company.

We have situation here our managers want us to give exception for business user.

Like we only set issue warning quota for higher management, based on the issue warning quota we need to alert the user twice a day if they cross the issue warning quota.

When I tried to set issue warning quota  exchange did not generate the warning messages for the users.

I am looking for some kind of script which check for the user issue warning quota and if they cross the warning quota need to generate the emails to the user with current mailbox size and issue warning quota showing on the email.

Someone can help me with this.

Thanks in advance.
0
Comment
Question by:alabkrishnan
  • 7
  • 4
  • 2
14 Comments
 
LVL 78

Expert Comment

by:David Johnson, CD, MVP
Comment Utility
the user/database must have a prohibit send/receive size and the warning will be greater than 50% of the prohibit send quota

The message associated with the Issue warning quota won’t be sent to the user unless the value of the quota is greater than 50% of the value specified in the Prohibit send quota. For example, if you set the Prohibit send quota to 8 MB, you must set the Issue warning quota to at least 4 MB. If you don’t, the Issue warning quota message won’t be sent.
http://technet.microsoft.com/en-us/library/aa998353(v=exchg.141).aspx
0
 
LVL 16

Accepted Solution

by:
Rajitha Chimmani earned 375 total points
Comment Utility
A sample code is given assuming that you will run this for single user. you need to specify the user's alias in the first line, and the sender email address,smtphostname in the last line. You can run this script on demand or using a scheduled task in specified intervals.

$User = username
$Details = Get-MailboxStatistics $user
$Mb = Get-Mailbox $User

$Size = [string]$Details.Value.tomb() + " MB"
$Quota = [string]($mb).IssueWarningQuota.Value.tomb() + " MB"
$Email = $Mb.primarysmtpaddress

$a = "<style>"
$a = $a + "HEAD{font-family:arial;color:black;}"
$a = $a + "BODY{font-family:arial;color:black;}"
$a = $a + "TABLE{border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;}"
$a = $a + "TH{border-width: 1px;padding: 5px;border-style: solid;border-color: black;background-color:#cccccc}"
$a = $a + "TD{border-width: 1px;padding: 5px;border-style: solid;border-color: black;background-color:#cccccc}"
$a = $a + "</style>"

$date = (get-date).getdatetimeformats()[43]


if($Details.StorageLimitStatus -eq "IssueWarning"){
#Create HTML File
$HtmlFile = "C:\quotastatus.htm"
New-Item $Htmlfile -type file -force

add-content $HtmlFile "$a <H2>Current Usage - $date</H2><table>"
add-content $HtmlFile "<tr><td>MailboxSize</td><td>$Size</td></tr>"
add-content $HtmlFile "<tr><td>WarningQuota</td><td>$Quota</td></tr>"
add-content $HtmlFile "</table>"

Function sendEmail
{ param($from,$to,$subject,$smtphost,$htmlFile)
$body = Get-Content $htmlFile
$smtp= New-Object System.Net.Mail.SmtpClient $smtphost
$msg = New-Object System.Net.Mail.MailMessage $from, $to, $subject, $body
$msg.isBodyhtml = $true
$smtp.send($msg)
}

sendEmail Exchange@domain.com $email "Warning:Quota over the limit" smtphostname $htmlfile
}

Open in new window

0
 
LVL 1

Author Comment

by:alabkrishnan
Comment Utility
Hi Ranjitha,

Thanks for posting the script let me test and keep you updated.

Thnaks
0
 
LVL 1

Author Comment

by:alabkrishnan
Comment Utility
Hi Ranjitha,

I have tested the script it works fine on exchange 2010, but in exchange 2013 Microsoft stopped checking the Storagelimitstatus I this case how we can execute the same script.

Please help me with this.

Thanks in advance.

Bala
0
 
LVL 16

Expert Comment

by:Rajitha Chimmani
Comment Utility
I have not worked on Exchange 2013 but we can try different condition instead of if($Details.StorageLimitStatus -eq "IssueWarning")

Can you post the output of below command so I will know the property to use?

Get-MailboxStatistics DisplayName | ft *quota*,*size
0
 
LVL 1

Author Comment

by:alabkrishnan
Comment Utility
Output for the command (Get-MailboxStatistics DisplayName | ft *quota*,*size)

TotalDeletedItemSize                                        TotalItemSize
--------------------                                        -------------
153.5 MB (160,922,849 bytes)                                598.8 MB (627,911,987 bytes)

thanks again for helping me on this.
0
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
LVL 16

Assisted Solution

by:Rajitha Chimmani
Rajitha Chimmani earned 375 total points
Comment Utility
Please try this condition

if($Details.TotalItemSize.Value.tomb() -ge $mb.IssueWarningQuota.Value.tomb())

Open in new window



Just noticed the earlier code has something missing. Correction below

$User = username
$Details = Get-MailboxStatistics $user
$Mb = Get-Mailbox $User

$Size = [string]$Details.TotalItemSize.Value.tomb() + " MB"
$Quota = [string]$mb.IssueWarningQuota.Value.tomb() + " MB"
$Email = $Mb.primarysmtpaddress

$a = "<style>"
$a = $a + "HEAD{font-family:arial;color:black;}"
$a = $a + "BODY{font-family:arial;color:black;}"
$a = $a + "TABLE{border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;}"
$a = $a + "TH{border-width: 1px;padding: 5px;border-style: solid;border-color: black;background-color:#cccccc}"
$a = $a + "TD{border-width: 1px;padding: 5px;border-style: solid;border-color: black;background-color:#cccccc}"
$a = $a + "</style>"

$date = (get-date).getdatetimeformats()[43]


if($Details.StorageLimitStatus -eq "IssueWarning"){
#Create HTML File
$HtmlFile = "C:\quotastatus.htm"
New-Item $Htmlfile -type file -force

add-content $HtmlFile "$a <H2>Current Usage - $date</H2><table>"
add-content $HtmlFile "<tr><td>MailboxSize</td><td>$Size</td></tr>"
add-content $HtmlFile "<tr><td>WarningQuota</td><td>$Quota</td></tr>"
add-content $HtmlFile "</table>"

Function sendEmail
{ param($from,$to,$subject,$smtphost,$htmlFile)
$body = Get-Content $htmlFile
$smtp= New-Object System.Net.Mail.SmtpClient $smtphost
$msg = New-Object System.Net.Mail.MailMessage $from, $to, $subject, $body
$msg.isBodyhtml = $true
$smtp.send($msg)
}

sendEmail Exchange@domain.com $email "Warning:Quota over the limit" smtphostname $htmlfile
}

Open in new window


Note: This code is written assuming that you have explicit limits set on mailbox. This does not work if the limits are set at database level.
0
 
LVL 1

Author Comment

by:alabkrishnan
Comment Utility
I gave the user name as my alias name but it gave me an error

The term 'ramasb' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spel
ling of the name, or if a path was included, verify that the path is correct and try again.
0
 
LVL 1

Author Comment

by:alabkrishnan
Comment Utility
ignore my last comment I figured it out.

I am very bad in PowerShell, thanks for helping me.

If I want to run for 100+ users how can I run this by selecting email from CSV also one more help. if I want to add below message to the content of the email.


{You have exceeded your mailbox quota.
The current size of your mailbox is (value) larger than your allocated size of (value).

Please reduce your mailbox size by deleting Items you don’t need from your mailbox and emptying your deleted items folder.
You can also contact the Solutions Center }
0
 
LVL 78

Assisted Solution

by:David Johnson, CD, MVP
David Johnson, CD, MVP earned 125 total points
Comment Utility
change quota message http://technet.microsoft.com/en-us/library/aa998037%28v=exchg.150%29.aspx
just add an import-csv, and a wrapper around the existing code
$users=import-csv -path c:\temp\users.csv
foreach ($mbuser in $users) {
$User = $mbuser.username
$Details = Get-MailboxStatistics $user
$Mb = Get-Mailbox $User

$Size = [string]$Details.TotalItemSize.Value.tomb() + " MB"
$Quota = [string]$mb.IssueWarningQuota.Value.tomb() + " MB"
$Email = $Mb.primarysmtpaddress

$a = "<style>"
$a = $a + "HEAD{font-family:arial;color:black;}"
$a = $a + "BODY{font-family:arial;color:black;}"
$a = $a + "TABLE{border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;}"
$a = $a + "TH{border-width: 1px;padding: 5px;border-style: solid;border-color: black;background-color:#cccccc}"
$a = $a + "TD{border-width: 1px;padding: 5px;border-style: solid;border-color: black;background-color:#cccccc}"
$a = $a + "</style>"

$date = (get-date).getdatetimeformats()[43]


if($Details.StorageLimitStatus -eq "IssueWarning"){
#Create HTML File
$HtmlFile = "C:\quotastatus.htm"
New-Item $Htmlfile -type file -force

add-content $HtmlFile "$a <H2>Current Usage - $date</H2><table>"
add-content $HtmlFile "<tr><td>MailboxSize</td><td>$Size</td></tr>"
add-content $HtmlFile "<tr><td>WarningQuota</td><td>$Quota</td></tr>"
add-content $HtmlFile "</table>"

Function sendEmail
{ param($from,$to,$subject,$smtphost,$htmlFile)
$body = Get-Content $htmlFile
$smtp= New-Object System.Net.Mail.SmtpClient $smtphost
$msg = New-Object System.Net.Mail.MailMessage $from, $to, $subject, $body
$msg.isBodyhtml = $true
$smtp.send($msg)
}

sendEmail Exchange@domain.com $email "Warning:Quota over the limit" smtphostname $htmlfile
}
} 

Open in new window

0
 
LVL 16

Assisted Solution

by:Rajitha Chimmani
Rajitha Chimmani earned 375 total points
Comment Utility
Try the following. I have removed the table from the email body as I feel you dont need it when you mention the size details in the message

Make sure the first column in csv file is Alias followed by user names as in

alias
user1
user2

$User = Import-csv filename.csv
foreach($entry in $User){
$Details = Get-MailboxStatistics $entry.alias
$Mb = Get-Mailbox $entry.alias

$Size = [string]$Details.TotalItemSize.Value.tomb() + " MB"
$Quota = [string]$mb.IssueWarningQuota.Value.tomb() + " MB"
$Email = $Mb.primarysmtpaddress

$a = "<style>"
$a = $a + "HEAD{font-family:arial;color:black;}"
$a = $a + "BODY{font-family:arial;color:black;}"
$a = $a + "TABLE{border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;}"
$a = $a + "TH{border-width: 1px;padding: 5px;border-style: solid;border-color: black;background-color:#cccccc}"
$a = $a + "TD{border-width: 1px;padding: 5px;border-style: solid;border-color: black;background-color:#cccccc}"
$a = $a + "</style>"

$date = (get-date).getdatetimeformats()[43]


if($Details.StorageLimitStatus -eq "IssueWarning"){

Function sendEmail
{ param($from,$to,$subject,$smtphost,$body)
$smtp= New-Object System.Net.Mail.SmtpClient $smtphost
$msg = New-Object System.Net.Mail.MailMessage $from, $to, $subject, $body
$msg.isBodyhtml = $true
$smtp.send($msg)
}

$body = 'You have exceeded your mailbox quota.<br/>The current size of your mailbox is '+ $Size + ', larger than your allocated size of ' + $Quota + '.<br/><br/>Please reduce your mailbox size by deleting Items you don’t need from your mailbox and emptying your deleted items folder.<br/>You can also contact the Solutions Center.'

sendEmail Exchange@domain.com $email "Warning:Quota over the limit" smtphostname $body
}
}

Open in new window

0
 
LVL 1

Author Closing Comment

by:alabkrishnan
Comment Utility
Excellent help
0
 
LVL 1

Author Comment

by:alabkrishnan
Comment Utility
thanks rajitha for helping me. much appricated
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
It’s a strangely common occurrence that when you send someone their login details for a system, they can’t get in. This article will help you understand why it happens, and what you can do about it.
The purpose of this video is to demonstrate how to set up an account with Mailchimp. This will be demonstrated using a Windows 8 PC. Tools Used are: Mailchimp.com Go to Mailchimp.com : Enter an Email, Username, and Password. Click Create My Acco…
This video discusses moving either the default database or any database to a new volume.

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now