question

George-8475 avatar image
0 Votes"
George-8475 asked LimitlessTechnology-2700 answered

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

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://docs.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.

windows-server-powershelloffice-outlook-itpro
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @George-8475

Thanks for your sharing about powershell.

It's recommended to post your solution as an answer, then click "Accept Answer" under it, which would benefit others who also have similar issues find the relevant information more easier.Thanks for your understanding.

0 Votes 0 ·
George-8475 avatar image
1 Vote"
George-8475 answered George-8475 edited

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://docs.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.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

LimitlessTechnology-2700 avatar image
0 Votes"
LimitlessTechnology-2700 answered

Hi George,

Thank you for your question.

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

https://docs.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.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.