Outlook Data Issue

This topic contains 2 replies, has 2 voices, and was last updated by  Vashen 4 years, 4 months ago.

  • Author
    Posts
  • #4700

    Vashen
    Participant

    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++;
    			}

     

     

  • #4726

    Art Beane
    Member

    What's the complete error message? What line causes the error?

    Where do all your variables get initiated? In the script as shown, $option, $date, $count and $totalcount are always equal to $null and the if clauses will never execute.

  • #4905

    Vashen
    Participant

    Hi Art,

     

    Thanks for your response. However, I've determined that the issue lay with outlook. As we use an archiving tool by Symantec, PS can't read the email message, thus causing it to fail.

     

    Vashen

You must be logged in to reply to this topic.