How to script the exchagne quota process seperately?

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.
LVL 1
alabkrishnanAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

David Johnson, CD, MVPOwnerCommented:
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
Rajitha ChimmaniCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
alabkrishnanAuthor Commented:
Hi Ranjitha,

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

Thnaks
0
Simplify Active Directory Administration

Administration of Active Directory does not have to be hard.  Too often what should be a simple task is made more difficult than it needs to be.The solution?  Hyena from SystemTools Software.  With ease-of-use as well as powerful importing and bulk updating capabilities.

alabkrishnanAuthor Commented:
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
Rajitha ChimmaniCommented:
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
alabkrishnanAuthor Commented:
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
Rajitha ChimmaniCommented:
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
alabkrishnanAuthor Commented:
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
alabkrishnanAuthor Commented:
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
David Johnson, CD, MVPOwnerCommented:
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
Rajitha ChimmaniCommented:
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
alabkrishnanAuthor Commented:
Excellent help
0
alabkrishnanAuthor Commented:
thanks rajitha for helping me. much appricated
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Email Software

From novice to tech pro — start learning today.