Solved

How to script the exchagne quota process seperately?

Posted on 2014-11-25
14
142 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 4
  • 2
14 Comments
 
LVL 82

Expert Comment

by:David Johnson, CD, MVP
ID: 40471274
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
ID: 40474114
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
ID: 40476556
Hi Ranjitha,

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

Thnaks
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 1

Author Comment

by:alabkrishnan
ID: 40476570
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
ID: 40476608
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
ID: 40477006
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
 
LVL 16

Assisted Solution

by:Rajitha Chimmani
Rajitha Chimmani earned 375 total points
ID: 40477030
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
ID: 40477061
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
ID: 40477096
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 82

Assisted Solution

by:David Johnson, CD, MVP
David Johnson, CD, MVP earned 125 total points
ID: 40477319
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
ID: 40477343
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
ID: 40479523
Excellent help
0
 
LVL 1

Author Comment

by:alabkrishnan
ID: 40479619
thanks rajitha for helping me. much appricated
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
In-place Upgrading Dirsync to Azure AD Connect
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Suggested Courses
Course of the Month3 days, 11 hours left to enroll

630 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