# Parse outlook appointment in shared calendar to check attachment

**URL:** <https://forums.powershell.org/t/parse-outlook-appointment-in-shared-calendar-to-check-attachment/15264>\
**Category:** PowerShell Help\
**Created:** [November 20, 2020, 3:02am UTC](https://forums.powershell.org/t/parse-outlook-appointment-in-shared-calendar-to-check-attachment/15264 "2020-11-20T03:02:30Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![webalive](https://avatars.discourse-cdn.com/v4/letter/w/ba8739/32.png) [@webalive](https://forums.powershell.org/u/webalive)\
**Post date:** [November 20, 2020, 3:02am UTC](https://forums.powershell.org/t/parse-outlook-appointment-in-shared-calendar-to-check-attachment/15264/1 "2020-11-20T03:02:30Z")

</div>

Hi All,

Maybe based on [https://powershell.org/forums/topic/outlook-automatic-export-and-calendar/](https://powershell.org/forums/topic/outlook-automatic-export-and-calendar/)

I’d like to create a loop in all appointments of many users (probably 15 actually) shared calendar and extract to excel a list with all appointments which don’t contain an attachment starting with “XX”.

I didn’t find how to access appointment 's attachment…

If somebody can help the noob I am…

&nbsp;

thanks to all

---

<div class="post-metadata">

**Author:** ![krzydoug](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/krzydoug/32/1008_2.png) [@krzydoug](https://forums.powershell.org/u/krzydoug)\
**Post date:** [November 22, 2020, 11:02am UTC](https://forums.powershell.org/t/parse-outlook-appointment-in-shared-calendar-to-check-attachment/15264/2 "2020-11-22T11:02:23Z")

</div>

What would this list contain? Just the name and date of the appointment?

---

<div class="post-metadata">

**Author:** ![webalive](https://avatars.discourse-cdn.com/v4/letter/w/ba8739/32.png) [@webalive](https://forums.powershell.org/u/webalive)\
**Post date:** [November 23, 2020, 4:38am UTC](https://forums.powershell.org/t/parse-outlook-appointment-in-shared-calendar-to-check-attachment/15264/3 "2020-11-23T04:38:40Z")

</div>

Hi Doug,

Thanks for reading

I need :

Person

Title

List of attachment filename

The goal is to verify if attachment filename start with “xx”

It seems to be very difficult to find info shared calendar objects.

---

<div class="post-metadata">

**Author:** ![krzydoug](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/krzydoug/32/1008_2.png) [@krzydoug](https://forums.powershell.org/u/krzydoug)\
**Post date:** [November 23, 2020, 4:41am UTC](https://forums.powershell.org/t/parse-outlook-appointment-in-shared-calendar-to-check-attachment/15264/4 "2020-11-23T04:41:53Z")

</div>

You said you wanted appointments where the filename DOES NOT start with XX, please clarify. Also, there may be more than one attachment, what are you planning for those situations?

---

<div class="post-metadata">

**Author:** ![webalive](https://avatars.discourse-cdn.com/v4/letter/w/ba8739/32.png) [@webalive](https://forums.powershell.org/u/webalive)\
**Post date:** [November 23, 2020, 5:11am UTC](https://forums.powershell.org/t/parse-outlook-appointment-in-shared-calendar-to-check-attachment/15264/5 "2020-11-23T05:11:25Z")

</div>

no sorry.  
each appointment has one more attachment file.  
One of them is delivery proof (AB.pdf), if it’s not present I have to add it.  
What I want is to verify if each appointment of each shared calendar has an attachment file which name starts with “AB” with .pdf extension (for example).  
Finally I’d like to get an output list in excel (or csv) of all appointments without this “AB.pdf” in attachment with field:

- Calendar’s owner
- Appointment’s object
- Date / Time

Hope it’s more clear…

thanks

&nbsp;

&nbsp;

&nbsp;

---

<div class="post-metadata">

**Author:** ![webalive](https://avatars.discourse-cdn.com/v4/letter/w/ba8739/32.png) [@webalive](https://forums.powershell.org/u/webalive)\
**Post date:** [November 23, 2020, 5:35am UTC](https://forums.powershell.org/t/parse-outlook-appointment-in-shared-calendar-to-check-attachment/15264/6 "2020-11-23T05:35:19Z")

</div>

In this way I can get all I need except attachment:

&nbsp;

```
Function Get-OutlookCalendar
{
    # load the required .NET types
    Add-Type -AssemblyName 'Microsoft.Office.Interop.Outlook'
    
    # access Outlook object model
    $outlook = New-Object -ComObject outlook.application

    # connect to the appropriate location
    $namespace = $outlook.GetNameSpace('MAPI')
    $Calendar = [Microsoft.Office.Interop.Outlook.OlDefaultFolders]::olFolderCalendar
    $folder = $namespace.GetSharedDefaultFolder($recipient, 9)
    # get calendar items
    $folder.items |

      Select-Object -Property Start, Organizer, Attachments

}
Get-OutlookCalendar | Out-GridView
```

---

<div class="post-metadata">

**Author:** ![krzydoug](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/krzydoug/32/1008_2.png) [@krzydoug](https://forums.powershell.org/u/krzydoug)\
**Post date:** [November 23, 2020, 8:57am UTC](https://forums.powershell.org/t/parse-outlook-appointment-in-shared-calendar-to-check-attachment/15264/7 "2020-11-23T08:57:24Z")

</div>

I’m not sure what you mean by “Appointments Object.” Hopefully this will help get you going.

This example assumes we are looping over the 15 accounts you’re trying to verify stored in the variable $userlist.

```
$userlist = 'smtp email account','alias','display name' # any of these work

# only need to define these once
Add-Type -AssemblyName ‘Microsoft.Office.Interop.Outlook’
$outlook = New-Object -ComObject outlook.application
$namespace = $outlook.GetNameSpace(‘MAPI’)
$olFolderCalendar = [Microsoft.Office.Interop.Outlook.OlDefaultFolders]::olFolderCalendar

# loop over all calendar owners and collect matching appointments
$appointments = foreach($user in $userlist)
{
    $recipient = $namespace.CreateRecipient($user)
    
    # verify account is found
    if($recipient.Resolve())
    {
        $CalendarFolder = $outlook.Session.GetSharedDefaultFolder($recipient, $olFolderCalendar)
        $calendarsharing = $CalendarFolder.GetCalendarExporter()
        $CalendarSharing.IncludeAttachments = $true

        # if any attachment filename matches ab...pdf it won't be collected
        $calendarsharing.Folder.Items |
            Where-Object {($($_.attachments).filename -match '^ab.+pdf$') -eq $false} |
                Foreach-Object {
                    [PSCustomObject]@{
                        Organizer = $user
                        Subject = $_.subject
                        StartTime = $_.start
                    }
                }
    }
    else
    {
        Write-Warning Unable to find account $user
    }
}

$appointments | Export-Csv c:\some\path\appointments_missing_ab-pdf.csv -NoTypeInformation
```

You could also choose to set the organizer property to $\_.organizer.

---

<div class="post-metadata">

**Author:** ![webalive](https://avatars.discourse-cdn.com/v4/letter/w/ba8739/32.png) [@webalive](https://forums.powershell.org/u/webalive)\
**Post date:** [November 24, 2020, 8:36am UTC](https://forums.powershell.org/t/parse-outlook-appointment-in-shared-calendar-to-check-attachment/15264/8 "2020-11-24T08:36:55Z")

</div>

Hi Doug,

thanks for that, it works fine.  
I was able to add categories, but I wasn’t able to restrict to only the 30 next days or to add where-object for categories too.  
Here’s what I tried :

```
$userlist = 'user1@domain.com', 'user2@domain.com' #,'alias','display name' # any of these work

# only need to define these once
Add-Type -AssemblyName ‘Microsoft.Office.Interop.Outlook’
$outlook = New-Object -ComObject outlook.application
$namespace = $outlook.GetNameSpace(‘MAPI’)
$olFolderCalendar = [Microsoft.Office.Interop.Outlook.OlDefaultFolders]::olFolderCalendar

# loop over all calendar owners and collect matching appointments
$appointments = foreach($user in $userlist)
{
    $recipient = $namespace.CreateRecipient($user)
    
    # verify account is found
    if($recipient.Resolve())
    {
        $CalendarFolder = $outlook.Session.GetSharedDefaultFolder($recipient, $olFolderCalendar)
        $calendarsharing = $CalendarFolder.GetCalendarExporter()
        $CalendarSharing.IncludeAttachments = $true
        $CalendarSharing.startDate = (get-date)
        $CalendarSharing.endDate = (get-date).AddDays(30)

        # if any attachment filename matches ab...pdf it won't be collected
        $calendarsharing.Folder.Items |
            Where-Object {
            
            ($($_.attachments).filename -match '^AB.+pdf$') -eq $false #-or ($($_.categories) -notlike "*orange*", "*rouge*") -eq $false
            
            } |
                Foreach-Object {
                    [PSCustomObject]@{
                        Organizer = $user
                        Subject = $_.subject
                        StartTime = $_.start
                        Categories =$_.categories
                    }
                }
    }
    else
    {
        Write-Warning Unable to find account $user
    }
}

$appointments | Export-Csv C:\MyPath\appointments_missing_ab-pdf.csv -delimiter ";" -Encoding UTF8
```

Take care of you.

---

<div class="post-metadata">

**Author:** ![krzydoug](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/krzydoug/32/1008_2.png) [@krzydoug](https://forums.powershell.org/u/krzydoug)\
**Post date:** [November 24, 2020, 11:10am UTC](https://forums.powershell.org/t/parse-outlook-appointment-in-shared-calendar-to-check-attachment/15264/9 "2020-11-24T11:10:36Z")

</div>

It appears that startdate and enddate are used for saveasical and forwardasical - they both honor the dates set. For what you’re trying to do I’d just go with having powershell filter

```
$userlist = 'user1@domain.com', 'user2@domain.com' #,'alias','display name' # any of these work
 
# only need to define these once
Add-Type -AssemblyName ‘Microsoft.Office.Interop.Outlook’
$outlook = New-Object -ComObject outlook.application
$namespace = $outlook.GetNameSpace(‘MAPI’)
$olFolderCalendar = [Microsoft.Office.Interop.Outlook.OlDefaultFolders]::olFolderCalendar
 
# loop over all calendar owners and collect matching appointments
$appointments = foreach($user in $userlist)
{
    $recipient = $namespace.CreateRecipient($user)
    
    # verify account is found
    if($recipient.Resolve())
    {
        $CalendarFolder = $outlook.Session.GetSharedDefaultFolder($recipient, $olFolderCalendar)
        $calendarsharing = $CalendarFolder.GetCalendarExporter()
        $CalendarSharing.IncludeAttachments = $true
 
        # if any attachment filename matches ab...pdf it won't be collected
        $calendarsharing.Folder.Items |
            Where-Object {
            
            ($($_.attachments).filename -match '^AB.+pdf$') -eq $false -and $_.start -gt (Get-Date) -and $_.end -lt (get-date).AddDays(30) #-or ($($_.categories) -notlike "*orange*", "*rouge*") -eq $false
            
            } |
                Foreach-Object {
                    [PSCustomObject]@{
                        Organizer = $user
                        Subject = $_.subject
                        StartTime = $_.start
                        Categories =$_.categories
                    }
                }
    }
    else
    {
        Write-Warning Unable to find account $user
    }
}
 
$appointments | Export-Csv C:\MyPath\appointments_missing_ab-pdf.csv -delimiter ";" -Encoding UTF8
```

Of course you could save those dates as variables or build parameters - this is just to demonstrate.

---

<div class="post-metadata">

**Author:** ![webalive](https://avatars.discourse-cdn.com/v4/letter/w/ba8739/32.png) [@webalive](https://forums.powershell.org/u/webalive)\
**Post date:** [November 24, 2020, 11:23am UTC](https://forums.powershell.org/t/parse-outlook-appointment-in-shared-calendar-to-check-attachment/15264/10 "2020-11-24T11:23:22Z")

</div>

Thanks Doug. A pleasure to learn with you. I 'll try to achieve the categories filter by myself.

---

<div class="post-metadata">

**Author:** ![webalive](https://avatars.discourse-cdn.com/v4/letter/w/ba8739/32.png) [@webalive](https://forums.powershell.org/u/webalive)\
**Post date:** [December 11, 2020, 3:04am UTC](https://forums.powershell.org/t/parse-outlook-appointment-in-shared-calendar-to-check-attachment/15264/11 "2020-12-11T03:04:19Z")

</div>

Hi Doug, All

Everything was fine with this script sinc few days ago… Now I always have this error :

Add-Type : Impossible de charger le fichier ou l’assembly ‘Microsoft.Office.Interop.Outlook, Version=12.0.0.0,  
Culture=neutral, PublicKeyToken=71e9bce111e9429c’ ou une de ses dépendances. Le fichier spécifié est introuvable.  
Au caractère Ligne:1 : 1

- Add-Type -AssemblyName ‘Microsoft.Office.Interop.Outlook’
- 

```auto

```

- CategoryInfo : NotSpecified: (🙂 [Add-Type], FileNotFoundException
- FullyQualifiedErrorId : System.IO.FileNotFoundException,Microsoft.PowerShell.Commands.AddTypeCommand

Do you know about any changes or similar issue ?

&nbsp;

thanks for answer

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:28pm UTC](https://forums.powershell.org/t/parse-outlook-appointment-in-shared-calendar-to-check-attachment/15264/12 "2024-05-16T20:28:09Z")

</div>


