none
Powershell script for Outlook 2016 inbox RRS feed

  • Question

  •  Hi,

     I need to create a PS to monitor Outlook inbox. The script needs to get total items in Inbox and total unread

     starting from today at 00:00  ending on today actual time, might want to inspect the subject as well.

     It is possible that there will be up to 30.000 emails hitting this inbox on a day. I want to out the output on a file excel or text.

     I have done some changes on a script the reads Outlook inbox but because of lack of experience I am simply not

     doing this correct.

      This is what I am working on.

     Add-type -assembly "Microsoft.Office.Interop.Outlook" | out-null
     $dagse = Get-Date -date $(Get-Date).AddDays(1) -format "MM/dd/yy"
     $dags = Get-Date -date $(Get-Date).AddDays(-1) -format "MM/dd/yy"
     $olFolders = "Microsoft.Office.Interop.Outlook.olDefaultFolders" -as [type]
     $outlook = new-object -comobject outlook.application
     $namespace = $outlook.GetNameSpace("MAPI")
     $folder = $namespace.getDefaultFolder($olFolders::olFolderInBox)   
     $folder.items |  Where-Object {$_.ReceivedTime -gt $dags -and $_.ReceivedTime -le $dagse } | Group-Object -Property RecipientAddress | Select name,count 
     $folderunread = $folder
     $folderunread.items |  Where-Object {$_.unread = $true}) | fl
    } #end function Get-OutlookInbox

     

    I get the total items but having problem with the unread items.

    thanks,

     


    Erro

    • Moved by Bill_Stewart Thursday, January 25, 2018 10:12 PM This is not "fix/debug/rewrite my script for me" forum
    Thursday, November 9, 2017 6:43 AM

All replies

  • $unread = $folder.items | Where-Object { $_.unread}
    $unread.Count


    \_(ツ)_/

    Thursday, November 9, 2017 7:54 AM
  • Hi Jrv,

     thanks for your reply This is how the script looks now. I am not getting anything in $unread.Count. there should be either true/false, so I need all the true i.e. not read and count them.

    Add-type -assembly "Microsoft.Office.Interop.Outlook" | out-null
     $dagse = Get-Date -date $(Get-Date).AddDays(1) -format "MM/dd/yy"
     $dags = Get-Date -date $(Get-Date).AddDays(-1) -format "MM/dd/yy"
     $olFolders = "Microsoft.Office.Interop.Outlook.olDefaultFolders" -as [type]
     $outlook = new-object -comobject outlook.application
     $namespace = $outlook.GetNameSpace("MAPI") 
     $folder = $namespace.getDefaultFolder($olFolders::olFolderInBox)    
     $folder.items |  Where-Object {$_.ReceivedTime -gt $dags -and $_.ReceivedTime -le $dagse } | Group-Object -Property RecipientAddress | Select name,count  
     $unread = $folder.items | Where-Object { $_.unread}
     $unread.Count
    } #end function Get-OutlookInbox

    thanks

      

     


    Erro


    • Edited by Erró Thursday, November 9, 2017 7:09 PM
    Thursday, November 9, 2017 1:16 PM
  • The code I posted gives you the count of all of the unread items which is what you asked for.

    If you want read items use this.

    $readitems = @($folder.items | Where-Object {!$_.unread})


    \_(ツ)_/

    Thursday, November 9, 2017 6:51 PM
  •  Hi,

      what I was trying to say is that unread can be

      unread    false

      unread   true

     this value will will change to "false" when the email has been read.

     I want only to count emails  with   unread   true 

     thanks


    Erro

    Thursday, November 9, 2017 7:08 PM
  • Yes.  That is correct.  The code works as expected.  "Unread" is a Boolean. We would just test it as I have.

    Start by learning the basics of programming and how we use logic in programs.  AS yourself "what are Booleans" for?

    Learn PowerShell: https://mva.microsoft.com/en-us/training-courses/getting-started-with-microsoft-powershell-8276


    \_(ツ)_/

    Thursday, November 9, 2017 7:15 PM