need a script that will email me when items in user1 mailbox inbox hits over 100

im looking for a script that will send me an email when the items in user1 inbox hits over 100
im using exchange 2010 sp1
dougdogAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
flaphead_comConnect With a Mentor Commented:
Aye, so save it a .ps1 and try it first, then you can create a schedule task.

What I like to do is create a cmd file that the scheduled task references and in the cmd have:

powershell <location of script.ps1?
0
 
flaphead_comCommented:
hope this helps.

Start by getting the users mailbox and the mailbox folder stats, where the folderpath is \Inbox

The is the ItemsInFolder is greater than 100, send an email

$User    = "user smtp"
$Items   = 100
$mailbox = get-mailbox $user | Get-MailboxFolderStatistics | Where {$_.FolderPath -eq "/Inbox"}
If($mailbox.ItemsInFolder -gt $items){
  $emailFrom  = "<from email address>"
  $emailto    = "<to email address>"
  $msgSubject = "$user Exceeds $items in inbox"
  $msgBody    = "$user has " + $mailbox.ItemsInFolder + " in inbox"
  $message    = New-Object Net.Mail.MailMessage($emailFrom, $emailto, $msgsubject, $msgbody)
  $smtp       = New-Object Net.Mail.SmtpClient("<smtp relay>")
  $smtp.Send($message)
  Write-Host "Email Sent"
}
0
 
dougdogAuthor Commented:
will i just save this asa *.ps1
then schedule it?
0
 
dougdogAuthor Commented:
perfect many thanks
0
All Courses

From novice to tech pro — start learning today.