Good morning everyone!
I am writing a script that checks for messages older than 60 minutes in a group of mailboxes. I have an issue where when I am using the GET-MAILBOXFOLDERSTATISTICS command, if there is a message in there, it says it is 6 hours in the future. I am assuming that this is GMT time.
My command within my script looks like this:
Get-MailboxFolderStatistics -Identity RISEVER -FolderScope INBOX -IncludeOldestAndNewestItems | where-object {$_.FolderPath -eq "/Inbox"} | Select-Object -Property OldestItemReceivedDate
The message (If it finds one) is the time + 6hours.
Is there anyway to get around this?
My total script looks like this:
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://EXCH01.domain.com/PowerShell/ -Authentication Kerberosimport-pssession $session -allowclobber
$date = (get-date).ToString('G')
$errorit = 0
### Set Mailbox identity
$mailboxes = 'MBX1','MBX2'
#### Query Inbox of mailbox to retrieve number of messages
foreach ($mailbox in $mailboxes)
{
$OIRD = Get-MailboxFolderStatistics -Identity $mailbox -FolderScope Inbox -IncludeOldestAndNewestItems | where-object {$_.FolderPath -eq "/Inbox"} | Select-Object -Property OldestItemReceivedDate
$OIRDInfo = $OIRD.oldestitemreceiveddate
if($OIRD.oldestitemreceiveddate -ne $null)
{
$OIRDInfo = $OIRD.oldestitemreceiveddate
#### Compare the time of the oldest mail in the Inbox to current time.
#### A mail is sent if more than 60 minutes has elapsed.
$compare = new-timespan -start $OIRDInfo -end $date
if ($compare.totalminutes -gt 60) {$errorit++}
}
}
$errorit
get-pssession | remove-pssession
Basically the script returns how many mailboxes have messages older than 60 minutes....The script as it sits is not going to alert for 7 hours.
Help me please!!
Kevin Hittle