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.