Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How to script the exchagne quota process seperately?

Posted on 2014-11-25
14
Medium Priority
?
149 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 84

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 1500 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
Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 
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 1500 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 84

Assisted Solution

by:David Johnson, CD, MVP
David Johnson, CD, MVP earned 500 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 1500 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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone 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

The core idea of this article is to make you acquainted with the best way in which you can export Exchange mailbox to PST format.
On September 18, Experts Exchange launched the first installment of the Help Bell, a new feature for Premium Members, Team Accounts, and Qualified Experts. The Help Bell will serve as an additional tool to help teams increase question visibility.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
Suggested Courses

885 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