none
Outlook 2013 becomes unusable after running script that accesses my calendar data RRS feed

  • Question

  • (from https://answers.microsoft.com/en-us/msoffice/forum/msoffice_outlook-mso_win10-mso_2013_release/outlook-2013-becomes-unusable-after-running-script/93463c2b-bd98-4b01-a482-1c8665a1c944?messageId=109d0d68-ad14-407b-b856-2a888e5c12b2)

     have written a PowerShell script that detects calendar conflicts (overlapping appointments).

    The script works like a charm, but after it has run, (32-bit) Outlook 2013 becomes unusable, for instance calendar operations fail with errors such as:

    Image

    or

    Image

    Sometimes the situation fixes itself after some time, sometimes I have to restart Outlook to get it back to normal operation.

    Any clue?

    P.S. FWIW, the script is a PowerShell script using the COM API, something like:

    $outlook=New-Object-ComObjectOutlook.Application

    # Ensure we are logged into a session

    $session=$outlook.Session

    $session.Logon()

    $olFolderCalendar=9

    $apptItems=$session.GetDefaultFolder($olFolderCalendar).Items

    $apptItems.Sort("[Start]")

    $apptItems.IncludeRecurrences =$true

    $restriction="[Start] >= '{0}' AND [Start] <= '{1}'"-f[datetime]::now.ToString("g"),([datetime]::now.AddDays($daysahead)).ToString("g")

    Write-Debug("Outlook Calendar Restrict() query: '{0}'"-f$restriction)

    $apptItems.Restrict($restriction) |sort-object-property@{Expression ="start"; ascending =$true},@{Expression ="end"; ascending =$true}

    [...]

    P.S. #2:

    Some context:

    - "About Microsoft Outlook" says "Microsoft Outlook 2013 (15.0.4953.1001) MSO (15.0.4953.1000) 32-bit, part of Microsoft Office Professional Plus 2013"

    - this is a "work" setup, with an Exchange (2010, IIRC) server

    - the machine is domain-joined

    - I've only tried starting Outlook in safe mode, to no avail

    Friday, September 15, 2017 11:26 AM

All replies

  • Hi,

    I notice that your issue happens when running a script for Outlook. To better resolve your issue, I would help to move the thread to Outlook for Developers forum for further troubleshooting.

    Additionally, please provide the complete script codes there so that the developers there can help to check your scripts and do more testing in their side.

    Thanks for your understanding.

    Best Regards,
    Winnie Liang


    Please remember to mark the replies as answers if they help. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    Monday, September 18, 2017 6:38 AM
  • Thx!

    Here's the entire script, FWIW:

    param([switch] $ignore_reserved, [int] $daysahead = 1000)
    
    $prev = $null
    
    $outlook = New-Object -ComObject Outlook.Application
    
    # Ensure we are logged into a session
    $session = $outlook.Session
    $session.Logon()
    
    $olFolderCalendar = 9
    $apptItems = $session.GetDefaultFolder($olFolderCalendar).Items
    $apptItems.Sort("[Start]")
    $apptItems.IncludeRecurrences = $true
    
    $restriction = "[Start] >= '{0}' AND [Start] <= '{1}'" -f [datetime]::now.ToString("g"), ([datetime]::now.AddDays($daysahead)).ToString("g")
    Write-Debug ("Outlook Calendar Restrict() query: '{0}'" -f $restriction)
    $apptItems.Restrict($restriction) | sort-object  -property @{Expression = "start"; ascending = $true}, @{Expression = "end"; ascending = $true} | % {
    if ($prev -ne $null)
    {
        if (`
            ([system.math]::min($_.end.ticks, $prev.end.ticks) - [system.math]::max($_.start.ticks,$prev.start.ticks) -gt 0) `
            -and `
            (!($_.Categories -like "*Holiday*") -and !($prev.Categories -like "*Holiday*")) `
            -and ($_.Subject -notmatch 'lunchtime' -and $prev.Subject -notmatch 'lunchtime') `
            -and ($_.Subject -notmatch 'Changer le filtre' -and $prev.Subject -notmatch 'Changer le filtre') `
            -and ((!($ignore_reserved)) -or (($_.Subject -notmatch 'Reserved for') -and ($prev.Subject -notmatch 'Reserved for') -and ($_.Subject -notmatch 'Venlo') -and ($prev.Subject -notmatch 'Venlo') -and ($_.Subject -notmatch 'Travel') -and ($prev.Subject -notmatch 'Travel') -and ($_.Subject -notmatch 'Figgo') -and ($prev.Subject -notmatch 'Figgo')))
            )
        {
            Write-Debug ("Adding {0} {1} {2} / {3} {4} {5}" -f $_.Subject, $_.Start, $_.End, $prev.Subject, $prev.Start, $prev.End)
    
            $obj = New-Object -TypeName PSObject
            Add-Member -InputObject $obj -MemberType NoteProperty -Name 'Subject1' -Value $_.Subject
            Add-Member -InputObject $obj -MemberType NoteProperty -Name 'Start1' -Value $_.start
            Add-Member -InputObject $obj -MemberType NoteProperty -Name 'End1' -Value $_.end 
            Add-Member -InputObject $obj -MemberType NoteProperty -Name 'Subject2' -Value $prev.subject
            Add-Member -InputObject $obj -MemberType NoteProperty -Name 'Start2' -Value $prev.start
            Add-Member -InputObject $obj -MemberType NoteProperty -Name 'End2' -Value $prev.end
            $obj
            # ([system.math]::min($_.end.ticks, $prev.end.ticks) - [system.math]::max($_.start.ticks,$prev.start.ticks))/1E7
            
          
        }
        else
        {
            Write-Debug ("Skipped {0} {1} {2} / {3} {4} {5}" -f $_.Subject, $_.Start, $_.End, $prev.Subject, $prev.Start, $prev.End)
        }
    }
    $prev = $_
    }
    
    
    
    
    


    • Edited by sba Monday, September 18, 2017 7:53 AM
    Monday, September 18, 2017 7:53 AM
  • Hi sba,

    What calendar operations did you do? I used your script on Outlook 2013(64-bit) and Outlook 2016(32-bit), it both works well and I did not get error adding/editing an appointment after the running script.

    I will build a 32bit Outlook virtual machine to test your issue as soon as possible. Your patience will be greatly appreciated.

    Best Regards,

    Terry

    Tuesday, September 19, 2017 10:08 AM
  • Hi Terry,

    Thx for looking into this.

    Here are some examples of abnormal behavior I get:

    - "Your server administrator..." is triggered by attempting to delete a meeting or one occurrence of a recurring meeting.

    - Adding a new meeting doesn't trigger an error.

    - Declining an occurrence of a recurring meeting does nothing, and does not yield an error message.

    If I close PowerShell ISE, the above operations work OK again.

    Unfreed resources?

    Tuesday, September 19, 2017 11:31 AM
  • Hi sba,

    I could not reproduce your issue using outlook 2013(32bit) too.

    Have you tried to test the script on other PC?

    If you tried to release the Outlook application at the end of the code, would the issue still exist?

    Here is the code.

    [System.Runtime.Interopservices.Marshal]::ReleaseComObject($outlook)

    Best Regards,

    Terry

    Wednesday, September 20, 2017 9:50 AM
  • Hi Terry,

    I still have to do more verifications, but it seems that this would indeed fix the problem.

    Note that this would mean that one cannot use Outlook Calendar while the script is running, though ;-(

    I'll keep you posted with the results of my further testing.

    Thanks a lot!

    Wednesday, September 20, 2017 3:19 PM
  • Hi sba,

    Has your original issue been resolved? If it has, I would suggest you mark the helpful reply as answer or provide your solution and mark as answer to close this thread. If not, please feel free to let us know your current issue.

    Thanks for understanding.

    Best Regards,

    Terry

    Friday, September 22, 2017 6:13 AM
  • I hate to say, but even with the resource-release statement added, I've just been able to repro the issue.

    Closing the PowerShell ISE where the script was running makes the problem go away.

    Friday, September 22, 2017 7:21 AM
  • Hi sba,

    I find that you create a new PSObject every time in the if...else statement, I would also suggest you release the object. Please try to test below code.

      $obj = New-Object -TypeName PSObject
    
            Add-Member -InputObject $obj -MemberType NoteProperty -Name 'Subject1' -Value $_.Subject
    
            Add-Member -InputObject $obj -MemberType NoteProperty -Name 'Start1' -Value $_.start
    
            Add-Member -InputObject $obj -MemberType NoteProperty -Name 'End1' -Value $_.end
    
            Add-Member -InputObject $obj -MemberType NoteProperty -Name 'Subject2' -Value $prev.subject
    
            Add-Member -InputObject $obj -MemberType NoteProperty -Name 'Start2' -Value $prev.start
    
            Add-Member -InputObject $obj -MemberType NoteProperty -Name 'End2' -Value $prev.end
    
            $obj
    
            # ([system.math]::min($_.end.ticks, $prev.end.ticks) - [system.math]::max($_.start.ticks,$prev.start.ticks))/1E7
    
            [System.Runtime.Interopservices.Marshal]::ReleaseComObject($obj)    

    Best Regards,

    Terry


    MSDN Community Support Please remember to click &quot;Mark as Answer&quot; the responses that resolved your issue, and to click &quot;Unmark as Answer&quot; if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, September 25, 2017 10:25 AM
  • Calling ReleaseComObject on a PSObject doesn't work:

    Exception calling "ReleaseComObject" with "1" argument(s): "The object's type must be __ComObject or derived from __ComObject.

    Parameter name: o"

    At C:\private_sba\PowerShell\CalendarConflicts.ps1:41 char:9

    +         [System.Runtime.Interopservices.Marshal]::ReleaseComObject($o ...

    +         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

        + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException

        + FullyQualifiedErrorId : ArgumentException

    Note:I'm typically running the script like this:

    CalendarConflicts.ps1-ignore_reserved-daysahead180|Out-GridView

    Monday, September 25, 2017 11:13 AM
  • Hi sba,

    What about running the code in PowerShell ISE directly instead of running the script?

    What about running the code in PowerShell instead of PowerShell ISE?

    Best Regards,

    Terry


    MSDN Community Support Please remember to click &quot;Mark as Answer&quot; the responses that resolved your issue, and to click &quot;Unmark as Answer&quot; if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, September 26, 2017 10:46 AM
  • Hi Terry,

    Running the "CalendarConflicts.ps1-ignore_reserved-daysahead180|Out-GridView" command line in PowerShell yields the same issue (and in the test I just made, closing the PowerShell host didn't solve the issue, I had to exit Outlook and start it anew).

    If by "running the code in PowerShell ISE" you mean using F5 to run the code, the only difference will be that the script will run with default values for the parameters (and that the output will not be piped into Out-GridView, of course). This also yields the same problem (but in that test, closing ISE restored normal operation in Outlook).

    Best regards,

    Stéphane.

     

    Tuesday, September 26, 2017 11:27 AM
  • Hi sba,

    What's your power shell version? Did you get the error when releasing $outlook? Could the code continue to run after getting the error? Besides, what about $obj=$null to release the obj?

    Best Regards,

    Terry


    MSDN Community Support Please remember to click &quot;Mark as Answer&quot; the responses that resolved your issue, and to click &quot;Unmark as Answer&quot; if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, September 29, 2017 1:01 AM
  • Adding

    $obj=$null

    to the loop and

    $outlook=$null

    at the end of the script didn't help.

    Monday, October 2, 2017 9:25 AM