Powershell how to read events from all calendars? (Outlook 2019 calendar on local computer)

George 101 Reputation points
2021-10-01T10:31:32.007+00:00

Hi,

I thought I might try my luck here.
I have 4 calendars (for simplicity they are named: Calendar, John, David, Jenny).
I inserted events into Calendar, and then John, David, and Jenny.
(These are all inside the same single Outllook account. The Outlook 2019 runs locally on my Desktop and is used by myself only. All 4 calendars are mine).

I would like to use Powershell to liste all events from all 4 calendars between a specific date range.

WHAT I TRIED (using code from ScriptGuy):

Add-type -assembly “Microsoft.Office.Interop.Outlook” | out-null  
 $olFolders = “Microsoft.Office.Interop.Outlook.OlDefaultFolders” -as [type]  
 $outlook = new-object -comobject outlook.application  
 $namespace = $outlook.GetNameSpace(“MAPI”)  
 $folder = $namespace.getDefaultFolder($olFolders::olFolderCalendar)  

Get-OutlookCalendar | where-object { $_.start -gt [datetime]"1 October 2021" -AND $_.start -lt [datetime]"3 October 2021"}  

PROBLEM: Only the events in "Calendar" are shown. The events in "John", "David", "Jenny" are not shown.
I took a snapshot of the combined calendars and powershell output. You can see the output is for "Calendar" only. The result shows 12345 (an event for "Calendar"), skips all events for John, David, Jenny, and then shows "FFFFFFFFFFFFFFFFFFFFFFFFFGGGGGGGGGGGGGGGGGGGGG" (the next event for "Calendar").

QUESTION: How do I show the events in the other 3 calendars please?

Many thanks.
136934-calendarjohndavidjenny2021-10-01-201440.jpg

ADDENDUM :

Okay I got it working. Need to add in a couple of lines:

The original code was from here:
https://devblogs.microsoft.com/scripting/use-powershell-to-export-outlook-calendar-information/

Then I read some VB documents from here:
https://learn.microsoft.com/en-us/office/vba/api/outlook.folders

The VB document gave me the idea to add these two lines:

$myNewFolder = $folder.Folders("John")
$myNewfolder.items

So the final function is now like this:

Function Get-OutlookCalendar  
{  
 Add-type -assembly “Microsoft.Office.Interop.Outlook” | out-null  
 $olFolders = “Microsoft.Office.Interop.Outlook.OlDefaultFolders” -as [type]  
 $outlook = new-object -comobject outlook.application  
 $namespace = $outlook.GetNameSpace(“MAPI”)  
 $folder = $namespace.getDefaultFolder($olFolders::olFolderCalendar)  
 $folder.items | Select-Object -Property Subject, Start, Duration, Location  
 $myNewFolder = $folder.Folders("John")  
 $myNewfolder.items  
} #end function Get-OutlookCalendar  

To execute it you just call it in powershell:

Get-OutlookCalendar  

It should list the events in the default Calendar , and also the events in the non-default calendar named "John".

This powershell command will list all appointments in Outlook between 1/10/2021 and 2/10/2021 inclusive

Get-OutlookCalendar | where-object { $_.start -gt [datetime]"1 October 2021" -AND $_.start -lt [datetime]"2 October 2021"}  

This powershell command will list all appointments in Outlook between 1/10/2021 and today inclusive

Get-OutlookCalendar | where-object { $_.start -gt [datetime]"1 October 2021" -AND $_.start -lt [datetime]::Today}  

Sort by date:

Get-OutlookCalendar | where-object { $_.start -gt [datetime]"1 October 2021" -AND $_.start -lt [datetime]"2 October 2021"} | sort-object Start  

List everything in the calendars:

$folder.items  
$myNewfolder.items  

That's all folks. I hope this helps some people. I notice a similar question was asked several times elsewhere by other people.

Outlook Management
Outlook Management
Outlook: A family of Microsoft email and calendar products.Management: The act or process of organizing, handling, directing or controlling something.
5,054 questions
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,449 questions
{count} votes

Accepted answer
  1. George 101 Reputation points
    2021-10-04T05:53:56.217+00:00

    Okay I got it working. Need to add in a couple of lines:

    The original code was from here:
    https://devblogs.microsoft.com/scripting/use-powershell-to-export-outlook-calendar-information/

    Then I read some VB documents from here:
    https://learn.microsoft.com/en-us/office/vba/api/outlook.folders

    The VB document gave me the idea to add these two lines:

    $myNewFolder = $folder.Folders("John")  
    $myNewfolder.items  
    

    So the final function is now like this:

     Function Get-OutlookCalendar  
     {  
      Add-type -assembly “Microsoft.Office.Interop.Outlook” | out-null  
      $olFolders = “Microsoft.Office.Interop.Outlook.OlDefaultFolders” -as [type]  
      $outlook = new-object -comobject outlook.application  
      $namespace = $outlook.GetNameSpace(“MAPI”)  
      $folder = $namespace.getDefaultFolder($olFolders::olFolderCalendar)  
      $folder.items | Select-Object -Property Subject, Start, Duration, Location  
      $myNewFolder = $folder.Folders("John")  
      $myNewfolder.items  
     } #end function Get-OutlookCalendar  
    

    To execute it you just call it in powershell:

    Get-OutlookCalendar

    It should list the events in the default Calendar , and also the events in the non-default calendar named "John".

    This powershell command will list all appointments in Outlook between 1/10/2021 and 2/10/2021 inclusive

     Get-OutlookCalendar | where-object { $_.start -gt [datetime]"1 October 2021" -AND $_.start -lt [datetime]"2 October 2021"}  
    

    This powershell command will list all appointments in Outlook between 1/10/2021 and today inclusive

     Get-OutlookCalendar | where-object { $_.start -gt [datetime]"1 October 2021" -AND $_.start -lt [datetime]::Today}  
    

    Sort by date:

     Get-OutlookCalendar | where-object { $_.start -gt [datetime]"1 October 2021" -AND $_.start -lt [datetime]"2 October 2021"} | sort-object Start  
    

    List everything in the calendars:

     $folder.items  
     $myNewfolder.items  
    

    That's all folks. I hope this helps some people. I notice a similar question was asked several times elsewhere by other people.

    By the way, if anyone wants to read all the contacts from Outlook using powershell, check out this link here:
    http://newdelhipowershellusergroup.blogspot.com/2014/03/getting-list-of-outlook-contacts-using.html
    It works well for me running Outlook 2019 (local version ie. no 365, no internet) on Windows 10.

    1 person found this answer helpful.

2 additional answers

Sort by: Most helpful
  1. Limitless Technology 39,506 Reputation points
    2021-10-04T10:04:39.227+00:00

    Hi George,

    Thank you for your question.

    I believe this article here can help you in some way to understand this scenario:

    https://learn.microsoft.com/en-us/powershell/module/exchange/get-calendardiagnosticlog?view=exchange-ps

    --------------------------------------------------------------------------------------------------------------------------

    If the answer is helpful, please vote positively and accept as an answer.

    0 comments No comments

  2. Tayler Schlottman 1 Reputation point
    2022-09-19T19:40:00.08+00:00

    How can I modify this to look for open time slots?

    0 comments No comments