1

I might be asking this in the wrong place so I apologize. I'm running a PS1 file to look in a specific folder, mark the emails as read, save the attachments and send me an email. For whatever reason, marking the emails as read, doesn't always work.

Since everything else works perfectly, I'll leave you with just what is not working

#Open Outlook and find emails from today
$ol = New-Object -ComObject Outlook.Application
$ns = $ol.GetNamespace('mapi')
$mb = $ns.Stores['some@email.com'].GetRootFolder()
$inbox = $mb.Folders['Reports']

$inbox.Items | ForEach-Object {$_.UnRead = $false}

If I run the script in ISE one line at a time, it works.
The problem arises when I select all and run in ISE, or as a PS1

Thanks!

  • Where and when do you run the code? Is it a service or web app? – Eugene Astafiev Aug 30 '21 at 16:01
  • What happens if you introduce a sleep of 1 second or so, like this: `$_.UnRead = $false; Start-Sleep 1`? This isn't ideal as a solution but as a debug step. – codewario Aug 30 '21 at 16:50
  • To Eugene, just from a VM that is running under my credentials, and this is my inbox we're attempting :) To Benden - nothing :( – JustSomeDude Aug 30 '21 at 18:34
  • 1
    @JustSomeDude, note that in order to notify other users you need to @-mention them, as I have done in this comment - but note that you can only notify _one_ user at a time. – mklement0 Jan 14 '22 at 23:23
  • As an update, this never worked for me. The attachment was a CSV file from SSRS, I learned of the atomfeed options and I'm reading directly from SSRS to update my needs – JustSomeDude Jan 14 '22 at 23:48

0 Answers0