My script below works, mostly.<\/p>\n
It searches my inbox looking for emails sent from WordFence, adds an object to a list, then deletes the email. Finally, it creates a CSV file from the object list.<\/p>\n
My issue is: It does not pull all<\/em><\/strong> of the emails so I have to run it several times to eventually collect them all. I have checked and delete() is in fact working. It is my search that appears to be the issue.<\/p>\n Thoughts?<\/p>\n $Outlook = New-Object -comobject outlook.application $events= @() $IPv4 = $item.Body.Split(“:”)[9].split(“U”)[0] $HostName = $item.Body.Split(“:”)[10].split(“U”)[0] $City = $item.Body.Split(“:”)[11] $events +=$NewObject $BaseFileName = \"C:\\PowerShell\\ReportOutput\" + $client_name_short + “\" + $ReportName + \"<\/em>” + (get-date).ToString(“yyyy-MM-dd_HHmm”) My script below works, mostly.<\/p>\n It searches my inbox looking for emails sent from WordFence, adds an object to a list, then deletes the email. Finally, it creates a CSV file from the object list.<\/p>\n My issue is: It does not pull all<\/em><\/strong> of the emails so I have to run it several times to eventually collect them all. I have checked and delete() is in fact working. It is my search that appears to be the issue.<\/p>\n Thoughts?<\/p>\n $Outlook = New-Object -comobject outlook.application $events= @() $IPv4 = $item.Body.Split(“:”)[9].split(“U”)[0] $HostName = $item.Body.Split(“:”)[10].split(“U”)[0] $City = $item.Body.Split(“:”)[11] $events +=$NewObject $BaseFileName = \"C:\\PowerShell\\ReportOutput\" + $client_name_short + “\" + $ReportName + \"<\/em>” + (get-date).ToString(“yyyy-MM-dd_HHmm”)
\n$NameSpace = $Outlook.GetNamespace(“MAPI”)
\n$olFolders = “Microsoft.Office.Interop.Outlook.olDefaultFolders” -as [type]
\n$FolderName = $namespace.getDefaultFolder($olFolders::olFolderInBox)<\/p>\n
\nforeach ($item in $FolderName.items){
\nif($item.Subject -like ‘wordpress User locked out<\/em>’){
\n$NewObject = ‘’ |Select-object SentOn, UserName, IPv4, HostName, City
\n$NewObject.SentOn = $item.SentOn
\n$NewObject.UserName = $item.Body.Split(“'”)[1]<\/p>\n
\n$NewObject.IPv4 = $IPv4.substring(1,$IPv4.Length-3)<\/p>\n
\n$NewObject.HostName = $HostName.substring(1,$HostName.Length-3)<\/p>\n
\n$NewObject.City = $City.Substring(1,$city.Length-18)<\/p>\n
\n$item.delete()
\n} # Bingo, found an email
\n} # For Each email in mailbox
\n$client_name_short = ‘YourNameHere’
\n$ReportName = ‘WordPress_Users_Locked’<\/p>\n
\n$CSVFile = $BaseFIleName + “.csv”
\n$events | ConvertTo-Csv -Delimiter “,” -NoTypeInformation | Out-File $CSVFile -Encoding ASCII<\/p>","upvoteCount":3,"answerCount":2,"datePublished":"2022-01-27T14:22:09.000Z","author":{"@type":"Person","name":"sheepd0g","url":"https://community.spiceworks.com/u/sheepd0g"},"suggestedAnswer":[{"@type":"Answer","text":"
\n$NameSpace = $Outlook.GetNamespace(“MAPI”)
\n$olFolders = “Microsoft.Office.Interop.Outlook.olDefaultFolders” -as [type]
\n$FolderName = $namespace.getDefaultFolder($olFolders::olFolderInBox)<\/p>\n
\nforeach ($item in $FolderName.items){
\nif($item.Subject -like ‘wordpress User locked out<\/em>’){
\n$NewObject = ‘’ |Select-object SentOn, UserName, IPv4, HostName, City
\n$NewObject.SentOn = $item.SentOn
\n$NewObject.UserName = $item.Body.Split(“'”)[1]<\/p>\n
\n$NewObject.IPv4 = $IPv4.substring(1,$IPv4.Length-3)<\/p>\n
\n$NewObject.HostName = $HostName.substring(1,$HostName.Length-3)<\/p>\n
\n$NewObject.City = $City.Substring(1,$city.Length-18)<\/p>\n
\n$item.delete()
\n} # Bingo, found an email
\n} # For Each email in mailbox
\n$client_name_short = ‘YourNameHere’
\n$ReportName = ‘WordPress_Users_Locked’<\/p>\n
\n$CSVFile = $BaseFIleName + “.csv”
\n$events | ConvertTo-Csv -Delimiter “,” -NoTypeInformation | Out-File $CSVFile -Encoding ASCII<\/p>","upvoteCount":3,"datePublished":"2022-01-27T14:22:09.000Z","url":"https://community.spiceworks.com/t/outlook-application-issue-reading-all-items/823291/1","author":{"@type":"Person","name":"sheepd0g","url":"https://community.spiceworks.com/u/sheepd0g"}},{"@type":"Answer","text":"