How do I get Outlook Appointments from Shared calendars

Hi All,

I’m trying to generate a list in which the current occupation of my colleagues is displayed for which I want to extract the data from Outlook (I can see the apointments of all colleagues in Outlook).

I’m trying to run this code

$UserList = 'adress1@example.com, adress2@example.com, adress3@example.com, adress4@example.com'
#User definition

Add-Type -AssemblyName 'Microsoft.Office.Interop.Outlook'
$Outlook = New-Object -ComObject outlook.application
$Namespace = $Outlook.GetNameSpace('MAPI')
$olFolderCalendar = [Microsoft.Office.Interop.Outlook.OLDefaultFolders]::olFolderCalendar

$appointments = foreach($User in $UserList)
{
    $recipient = $Namespace.CreateRecipient($User)

    if($recipient.Resolve())
    {
        $CalendarFolder = $Outlook.Session.GetSharedDefaultFolder($recipient,$olFolderCalendar)
        $CalendarSharing = $CalendarFolder.GetCalendarExporter()
        
        $CalendarSharing.Folder.Items 
        ForEach-Object
        {
            [PSCustomObject]@{
                Organizer = $User
                Subject = $_.subject
                StartTime = $_.start
                }
        }
    }
    else
    {
        Write-Warning "Unable to Find Account  $UserList"
    }
}

$Appointments | select -Property Start, End, BusyStatus, Categories, Subject, IsRecurring, Organizer

Yes, I used a lot of googling to come up with this, but most of it is from this:

Topic: Parse outlook appointment in shared calendar to check attachment | PowerShell.org

 

 

When I use my E-Mail-Adress I get the results I want, although they are unfiltered at the moment.
But when I use the E-Mail of someone else I get the following error message:

Der versuchte Vorgang konnte nicht ausgeführt werden. Ein Objekt wurde nicht gefunden.
In Zeile:19 Zeichen:9
+ $CalendarSharing = $CalendarFolder.GetCalendarExporter()
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OperationStopped: (:) [], COMException
+ FullyQualifiedErrorId : System.Runtime.InteropServices.COMException

 

 

Thanks in advance.

 

Couldn’t make out anything from the error. Can you help converting it to English.

Sure,

The attempted operation could not be performed. Object not found.
In Row:19 Character:9
+ $CalendarSharing = $CalendarFolder.GetCalendarExporter()
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OperationStopped: (:) [], COMException
+ FullyQualifiedErrorId : System.Runtime.InteropServices.COMException

Regards.

Seems like permission issue with id you are using. Does that ID have permission. It looks $CalendarFolder is empty with id you are getting error. Wrap it in a try catch block or a trap block with something like Write-Host $_. Also check if $receipent is populated or not

$CalendarFolder has some content but “FolderPath” and “FullFolderPath” are only filled in when I search for my own E-Mail address when I use someone elses its not filled in, except this and the “StoreID” and “EntryID” the values are the same.

$recipient is also populated, it is the same except for “Address”, “EntryID” and “Name”

I would suggest to run this with some admin account. Seems it is unable to get data. From script point if it works for one should work for other mail too. Have you tried with multiple different mail

I tried to run Powershell as admin and I got a few more errors, it seemed like it didn’t know the -ComObject stuff.
I tried to run it by someone else and he could also only get his appointments and not mine, he also tried to run Powershell as administrator and got the same errors.

May the problem be that we are running our own Exchange server and not Exchange Online?

If you run the script as admin then outlook needs to be run as admin. Have you tried my Export-OutlookSharedCalendar function?