Powershell to get the number of mails in the Inbox and number of unread emails in Inbox

Powershell using Outlook.Application to pull out the mailbox details

$outlook = new-object -com Outlook.Application
$session = $outlook.Session
$session.Logon()
$inbox = $outlook.session.GetDefaultFolder(6)
$unreadCount = (%{$inbox.Items | where {$_.UnRead}}).Count
Write-Host $unreadCount
$ItemCount = (%{$inbox.Items }).Count
Write-Host $ItemCount

 

3 thoughts on “Powershell to get the number of mails in the Inbox and number of unread emails in Inbox

  1. Thanks for this shell command, I was wondering if you can help me alter this command so it checks every 30 minutes on an inbox for a user to see if there is an unread email older then 30 minutes and if so send an email alert? thanks in advance!

  2. Thanks for this shell command, I was wondering if you can help me alter this command so it checks every 30 minutes on an inbox for a user to see if there is an unread email older then 30 minutes and if so send an email alert? thanks in advance!
    Reply

  3. This modification works for situations where 1 is returned as the result:
    $outlook = new-object -com Outlook.Application
    $session = $outlook.Session
    $session.Logon()
    $inbox = $outlook.session.GetDefaultFolder(6)
    [array]$unreadCount = @(%{$inbox.Items | where {$_.UnRead}}).Count
    Write-Host $unreadCount
    [array]$ItemCount = @(%{$inbox.Items }).Count
    Write-Host $ItemCount

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s