Answered by:
Powershell Script to create new Outlook Meeting

Question
-
I am working on a powershell script to create outlook meetings.
My script works, but i am having issues when I try to add an attendee, it creates the meeting without any attendees.
Here is the content of my script, perhaps someone can point me in the right direction?
As a note, i am trying to add an attendee using their SMTP Email address.
function Add-CalendarMeeting { param ( [cmdletBinding()] # Subject Parameter [Parameter( Mandatory = $True, HelpMessage="Please provide a subject of your calendar invite.")] [Alias('sub')] [string] $Subject, #Body parameter [Parameter( Mandatory = $True, HelpMessage="Please provide a description of your calendar invite.")] [Alias('bod')] [string] $Body, # Send Meeting Invites to Required Attendees [Parameter( Mandatory = $True, HelpMessage = "Please provide email address of desired attendee.")] [Alias('invitee')] [string] $ReqAttendee, #Location Parameter [string] $Location = "Virtual", # Importance Parameter [int] $Importance = 1, # Set Reminder Parameter [bool] $EnableReminder = $True, # Metting Start Time Parameter [datetime] $MeetingStart =(Get-Date), # Meeting time duration parameter [int] $MeetingDuration = 120, # by Default Reminder Duration [int] $Reminder = 15 ) BEGIN { # Create a new appointment using Powershell $outlookApplication = New-Object -ComObject 'Outlook.Application' # Creating a instatance of Calenders $newCalenderItem = $outlookApplication.CreateItem('olAppointmentItem') } PROCESS { $newCalenderItem.Subject = $Subject $newCalenderItem.Body = $Body $newCalenderItem.Location = $Location $newCalenderItem.ReminderSet = $EnableReminder $newCalenderItem.Importance = $importance $newCalenderItem.RequiredAttendees.Add($ReqAttendee) # $newCalenderItem.RequiredAttendees = $ReqAttendee $newCalenderItem.ReminderMinutesBeforeStart = $Reminder $newCalenderItem.Start = $MeetingStart $newCalenderItem.Duration = $MeetingDuration } END { Write-Verbose "Saving Calender Item" $newCalenderItem.Save() # if you want to see the calendar invite un-comment the below line #un-comment it ==> $newCalenderItem.Display($True) } }
Thank you very much for your assistance.
- Moved by Steve Fan Wednesday, October 26, 2016 7:07 AM
Tuesday, October 25, 2016 2:04 PM
Answers
-
Here is a complete, tested and working example:
$ol = New-Object -ComObject Outlook.Application $meeting = $ol.CreateItem('olAppointmentItem') $meeting.Subject = 'Test # 4' $meeting.Body = 'Let''s have a meeting' $meeting.Location = 'Virtual' $meeting.ReminderSet = $true $meeting.Importance = 1 $meeting.MeetingStatus = [Microsoft.Office.Interop.Outlook.OlMeetingStatus]::olMeeting $meeting.Recipients.Add('jsmith@contoso.net') $meeting.Recipients.Add('mjones@contoso.net') $meeting.ReminderMinutesBeforeStart = 15 $meeting.Start = [datetime]::Today.Adddays(1) $meeting.Duration = 30 $meeting.Send()
\_(ツ)_/
- Marked as answer by Michael Toombs Thursday, October 27, 2016 9:48 PM
Wednesday, October 26, 2016 9:55 PM
All replies
-
Hi,
This forum is for general questions and feedback related to Office 2016 and Office 365 ProPlus. Since your question is more related to PowerShell Script, I'll move it to the following forum for more efficient support:
https://social.technet.microsoft.com/Forums/office/en-US/home?forum=winserverpowershell
The reason why we recommend posting appropriately is you will get the most qualified pool of respondents, and other partners who read the forums regularly can either share their knowledge or learn from your interaction with us. Thank you for your understanding.
Steve Fan
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.Wednesday, October 26, 2016 7:06 AM -
Hi Michael,
Please notice this line:
$newCalenderItem.RequiredAttendees.Add($ReqAttendee)
I'd prefer to use:
$newCalenderItem.Recipients.Add($ReqAttendee)
Also, at the end of this script, add this:
$newCalenderItem.send()
$newCalenderItem.Save()
Besides, you missed the name of this function at the bottom:
Add-CalendarMeeting
If you have any more feedback about this issue, welcome post here.
Have a nice day!
Best regards,
Andy
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.
- Edited by Hello_2018 Wednesday, October 26, 2016 7:32 AM
Wednesday, October 26, 2016 7:30 AM -
Check out the vbscript example on the link below.
https://msdn.microsoft.com/en-us/library/office/ff866462.aspxAccording to the vbs example the below powershell should work, however I have not tested it.
$Attendee = $newCalenderItem.Recipients.Add($ReqAttendee)
$Attendee.Type = 'olRequired'Wednesday, October 26, 2016 7:37 AM -
So, I've made a few changes, but I am still running into issues.
Like I said before, the script is successfully creating an Appointment on my Calendar.
The part that is not working, is that the Appointment has no Attendees.
Here is my updated Script:
function Add-CalendarMeeting { param ( [cmdletBinding()] # Subject Parameter [Parameter( Mandatory = $True, HelpMessage="Please provide a subject of your calendar invite.")] [Alias('sub')] [string] $Subject, #Body parameter [Parameter( Mandatory = $True, HelpMessage="Please provide a description of your calendar invite.")] [Alias('bod')] [string] $Body, # Send Meeting Invites to Required Attendees [Parameter( Mandatory = $True, HelpMessage = "Please provide email address of desired attendee.")] [Alias('invitee')] [string] $ReqAttendee, #Location Parameter [string] $Location = "Virtual", # Importance Parameter [int] $Importance = 1, # Set Reminder Parameter [bool] $EnableReminder = $True, # Metting Start Time Parameter [datetime] $MeetingStart =(Get-Date), # Meeting time duration parameter [int] $MeetingDuration = 120, # by Default Reminder Duration [int] $Reminder = 15 ) BEGIN { # Create a new appointment using Powershell $outlookApplication = New-Object -ComObject 'Outlook.Application' # Creating a instatance of Calenders $newCalenderItem = $outlookApplication.CreateItem('olAppointmentItem') } PROCESS { $newCalenderItem.meetingstatus.olMeeting $newCalenderItem.Subject = $Subject $newCalenderItem.Body = $Body $newCalenderItem.Location = $Location $newCalenderItem.ReminderSet = $EnableReminder $newCalenderItem.Importance = $importance $newCalenderItem.ReminderMinutesBeforeStart = $Reminder $newCalenderItem.Start = $MeetingStart $newCalenderItem.Duration = $MeetingDuration $newCalenderItem.recipients.add($ReqAttendee) $newCalenderItem.send() } END { Write-Verbose "Saving Calender Item" $newCalenderItem.Save() # if you want to see the calendar invite un-comment the below line #un-comment it ==> $newCalenderItem.Display($True) } }
I am calling the function like this:
Add-CalendarMeeting -Subject "Message Subject" -Body "Message Body" -ReqAttendee "bob@example.com" -MeetingStart "10/31/16 2:00pm"
Here is the output that I get from calling the function:
Application : Microsoft.Office.Interop.Outlook.ApplicationClass Class : 4 Session : System.__ComObject Parent : System.__ComObject Address : AddressEntry : System.__ComObject AutoResponse : DisplayType : 0 EntryID : 00000000812B1FA4BEA310199D6E00DD010F5402000001906D0069006B00650040006400610072006B0067006100720 06100670065002E0063006F006D00000053004D005400500000006D0069006B00650040006400610072006B00670061 0072006100670065002E0063006F006D000000 Index : 1 MeetingResponseStatus : 0 Name : bob@example.com Resolved : True TrackingStatus : 0 TrackingStatusTime : 1/1/4501 12:00:00 AM Type : 1 PropertyAccessor : System.__ComObject Sendable : True Press any key to continue ...
Any thoughts would be greatly appreciated.
Thank you very much for your able assistance.
Wednesday, October 26, 2016 8:24 PM -
You copied your code from here: https://gallery.technet.microsoft.com/office/Create-Meeting-is-MS-f117778d#content
The code has many errors and is very badly designed. It never worked and the author has never responded to any requests.
In 2010 Microsoft changed the object model for appointments so the code will not work on current versions of Outlook.
\_(ツ)_/
- Edited by jrv Wednesday, October 26, 2016 9:43 PM
Wednesday, October 26, 2016 9:40 PM -
Here is a complete, tested and working example:
$ol = New-Object -ComObject Outlook.Application $meeting = $ol.CreateItem('olAppointmentItem') $meeting.Subject = 'Test # 4' $meeting.Body = 'Let''s have a meeting' $meeting.Location = 'Virtual' $meeting.ReminderSet = $true $meeting.Importance = 1 $meeting.MeetingStatus = [Microsoft.Office.Interop.Outlook.OlMeetingStatus]::olMeeting $meeting.Recipients.Add('jsmith@contoso.net') $meeting.Recipients.Add('mjones@contoso.net') $meeting.ReminderMinutesBeforeStart = 15 $meeting.Start = [datetime]::Today.Adddays(1) $meeting.Duration = 30 $meeting.Send()
\_(ツ)_/
- Marked as answer by Michael Toombs Thursday, October 27, 2016 9:48 PM
Wednesday, October 26, 2016 9:55 PM -
Thank you very much.
I will give this a try and see if my script works any better.
I will update here with what I find.
- Edited by Michael Toombs Thursday, October 27, 2016 9:48 PM Spelling errors
Thursday, October 27, 2016 9:38 PM -
@jrv Your Updated Code worked perfectly!
Thank you again for your excellent assistance.
Thursday, October 27, 2016 9:48 PM -
Glad that it helped.
\_(ツ)_/
Thursday, October 27, 2016 10:00 PM -
Hi Michael,
I am new to powershell script. How would I save the file and run the script. Is it powershell script?
Regards,
Veduri
Wednesday, November 30, 2016 5:38 AM -
Put these codes into your powershell ISE, then saving as .ps1 file.
If you wanted to run it, just need to open the cmd or powershell console, type .\xx.ps1, you'd better check your privileges(runas admin) & policies(unrestricted or something else) before running it.
Best regards,
Andy
Please remember to mark the replies as answers if they help.
If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.Wednesday, November 30, 2016 5:59 AM -
This works great.. Except one cannot do formatted text within the Body.
I am using this to create a reminder in Outlook 2010. I have MUCH more in the Body than a
single sentence. In fact I am adding the contents of a RTF file to the body. However Outlook
is not parsing so it goes in as plain text.
It looks garbled of course. RTF plain text.
I was hoping for HTML for colored text and formatting, but 2010 does not support it for Calendar
only Email. So I tried RTF and its RTF plain text garble.
<pre>
{\rtf1\adeflang1025\ansi\ansicpg1252\uc1\adeff0\deff0\stshfdbch0\stshfloch0\stshfhich0\stshfbi0\deflang1033\deflangfe1033\themelang1033\themelangfe0\themelangcs0{\fonttbl{\f0\fbidi \froman\fcharset0\fprq2{\*\panose 02020603050405020304}Times New Roman;}{\f0\fbidi \froman\fcharset0\fprq2{\*\panose 02020603050405020304}Times New Roman;} {\flomajor\f31500\fbidi \froman\fcharset0\fprq2{\*\panose 02020603050405020304}Times New Roman;}{\fdbmajor\f31501\fbidi ...
</pre>
I have found nothing to resolve that issue.
Thanks again.. I'll still use with plain text for now.
Tim
- Edited by tmanochehri Tuesday, July 11, 2017 10:24 PM
Tuesday, July 11, 2017 10:19 PM -
Hi Tim
I am facing the very same issue.
Did you finally got an answer?
Thanks
Bruno
Bruno
Thursday, February 8, 2018 9:16 AM -
Outlook/email use HTML and not RTF.
\_(ツ)_/
Thursday, February 8, 2018 9:19 AM