1

How do you create an Outlook Appointment / Meeting in PowerShell?

Doug
  • 6,446
  • 9
  • 74
  • 107

1 Answers1

1

The following code will create an Outlook Appointment in PowerShell.

Function Create-Appointment(){
    [CmdletBinding()]
    param (
        [Parameter(Mandatory=$true)][String]$Subject,
        [Parameter(Mandatory=$true)][DateTime]$MeetingStart,
        [Parameter()][String]$Recipients,
        [Parameter()][String]$Categories,
        [Parameter()][String]$Location,
        [Parameter()][String]$Body=$Subject,
        [Parameter()][int]$ReminderMinutesBeforeStart=15,
        [Parameter()][int]$DurationInMinutes=30
    )

    $ol = New-Object -ComObject Outlook.Application
    $meeting = $ol.CreateItem('olAppointmentItem')

    if($ReminderMinutesBeforeStart -gt 0){
        $meeting.ReminderSet = $true
        $meeting.ReminderMinutesBeforeStart = $ReminderMinutesBeforeStart
    }

    if($PSBoundParameters.ContainsKey('Recipients')){
        foreach($email in $Recipients -split ";"){
            if($email -ne ''){
                $meeting.Recipients.Add($email)
            }
        }
        $meeting.MeetingStatus = [Microsoft.Office.Interop.Outlook.OlMeetingStatus]::olMeeting
    } else {
        $meeting.MeetingStatus = [Microsoft.Office.Interop.Outlook.OlMeetingStatus]::olNonMeeting
    }

    if($PSBoundParameters.ContainsKey('Location')){
        $meeting.Location = $Location
    }

    if($PSBoundParameters.ContainsKey('Categories')){
        $meeting.Categories = $Categories
    } 

    $meeting.Subject = $Subject
    $meeting.Body = $Body
    $meeting.Start = $MeetingStart
    $meeting.Duration = $DurationInMinutes
    $meeting.Save()    
    $meeting.Send()    
}
Doug
  • 6,446
  • 9
  • 74
  • 107
  • 1
    Nice; a few tips: `[Parameter(Mandatory=$true)` can be simplified to `[Parameter(Mandatory)`; `[Parameter()]` is redundant. `$email in $Recipients -split ";"` is better and more robustly expressed as `($Recipients -split ";" -ne '').Trim()`, which obviates the need for `if($email -ne '')` – mklement0 Sep 19 '22 at 22:20