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.