I was wondering if someone would be able to help me please.
I’m after data from a folder within outlook, then to count the amount of data.
PS processes the data fine, but when it gets to single digits, in this case, 9/05/2013 it gives the error “You cannot call a method on a null-valued expression.”. It works fine up till the date changes to a single digit. Even formatting the date to be 09 I get the error. Can anyone see any issues with my code?
So basically it gives the user some options. Option 1 is pretty much a mass dump of outlook data with no filtering. However option 2 is meant to just filter the past 7 days and give back the totals. Works fine … till you hit single digit dates.
Thanks in advance.
$SevenDaysAgo = (Get-Date).AddDays(-7).ToString("dd/MM/yyy") $Today = (Get-Date).ToString("dd/MM/yyy") $outlook = new-object -com Outlook.Application $outlook.Session.GetDefaultFolder(6).Folders | ? {$_.FolderPath -match "\\Inbox\\Remedy$"} | % {$_.items} | ? {$_.subject -match "^Incident\sINC\d{12}"} | % { $subject = $_.subject -replace "^[\w\s]+(?=INC\d{12})|(?<=INC\d{12})[\D\d]+",$null $ReceivedTime = $_.ReceivedTime.ToString("dd/MM/yyy") if ($option -eq "2") { if ($Date -ne $ReceivedTime) { if ($date) { Write-Host "$date - $count" } $count = $null; $date = $_.ReceivedTime.ToString("dd/MM/yyy") Write-Output $ReceivedTime } $count++; $totalcount++; }