I had to write a PowerShell script for Exchange 2010 that sends an email to a user when his mailbox size exceeded 1Gb. Here is the script:
If ((Get-PSSnapin | where {$_.Name -match "Exchange.Management"}) -eq $null)
{
Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010
}
$toArray=Get-MailboxServer | Get-Mailbox | foreach-object {$email = $_.primarysmtpaddress; $_ | Get-MailboxStatistics | Where {$_.TotalItemSize.Value.ToMB() -gt 1024 } | select @{ expression={$email}}}
$from="from@from.com"
Foreach ($to in $toArray)
{
$s=[string]$to
[int]$Start = $s.IndexOf("=")
[int]$End = $s.IndexOf("}")
[string]$ss=$s.Substring($Start+1,$End-$start-1)
$messageParameters = @{
smtpServer = “smtp server”
From = [string]$from
To = $ss
Subject = "Warning!"
Body = “Your mailbox is over 1Gb in size. Please delete old email messages to reduce size of your mailbox”
}
Send-MailMessage @messageParameters -BodyAsHtml
}
Creating Scheduled Tasks for Exchange 2010 PowerShell Scripts:
http://www.mikepfeiffer.net/2010/02/creating-scheduled-tasks-for-exchange-2010-powershell-scripts/
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -command ". 'C:\Program Files\Microsoft\Exchange Server\V14\bin\RemoteExchange.ps1'; Connect-ExchangeServer -auto; c:\Scripts\MoveMailboxes.ps1"
Thank you for visiting my blog. It is all started with Microsoft Word/Excel document recovery method that I implemented at work. My coworkers were so impressed that they “forced” me to create a webpage and post steps required for that method. Later I realized that not many people are reading this blog and I decided to keep it for myself and post here some code and ideas that I could reuse for the future. If you find my posts useful drop a comment for me.
Friday, January 6, 2012
Email warning when mailbox size is over limit on Exchange 2010 with PowerShell Script
Labels:
PowerShell
Subscribe to:
Post Comments (Atom)
2 comments:
can i copy it and make it my own? :)
Absolutely! Thanks!
Post a Comment