Solved

How to script the exchagne quota process seperately?

Posted on 2014-11-25
14
133 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
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
 
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
Being driven mad by email signature updates?

Having to make a change to your users’ email signatures, yet again? Feel like your head is going to explode? Rely on an Exclaimer email signature management solution to make the process simple!

 
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 78

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Lotus Notes – formerly IBM Notes – is an email client application, while IBM Domino (earlier Lotus Domino) is an email server. The client possesses a set of features that are even more advanced as compared to that of Outlook. Likewise, IBM Domino is…
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.
To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

920 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

16 Experts available now in Live!

Get 1:1 Help Now