This is in continuation to my previous post regarding working with Calendar items, in my last post we saw how can we get calendar items from a user mailbox and report them.
Below is the post if you haven't checked that yet.
Working with Calendar Items using EWS managed API
As we are going to use the EWS make sure you met all the prerequisites before you plan to run this script.
- Admin account should have application impersonation rights, you can follow this MSDN post to setup the permissions.
- Install EWS managed API on system where you plan to run the script from, if API is not installed, download the same from here
Below is the sample code.
POWERSHELL
$Appointment = New-Object Microsoft.Exchange.WebServices.Data.Appointment -ArgumentList $service
$Appointment.Subject = "Test Meeting - Daily Team Meeting - EWS";
$Appointment.Body = "The purpose of this meeting is to discuss status.";
$Appointment.Start = (get-date).adddays($n);
$Appointment.End = $Appointment.Start.AddHours(2);
$Appointment.Location = "Conf Room";
$Appointment.RequiredAttendees.Add("testuser1@testdomain.com");
$Appointment.RequiredAttendees.Add("testuser2@testdomain.com");
$Appointment.OptionalAttendees.Add("testuser3@testdomain.com");
$Appointment.Save()
POWERSHELL
POWERSHELL
POWERSHELL
Once you Save the meeting you will see a meeting on your calender, and the invitation will be sent to RequiredAttendees and OptionalAttendees as well.
POWERSHELL
POWERSHELL
below is full script code to run a meeting in user calender this could be handy to populate lots of meeting to prep the test mailbox for migraton testing.
POWERSHELL
POWERSHELL
POWERSHELL
POWERSHELL
param(
$user=$cred.UserName,
$pass=$cred.GetNetworkCredential().password,
$impdUser="sunil.chauhan@testdomain.com" )
$EWSDllpath='C:\Program Files\Microsoft\Exchange\Web Services\2.0\Microsoft.Exchange.WebServices.dll'
$EwsUrl = 'https://outlook.office365.com/EWS/Exchange.asmx'
Import-Module $EWSDllpath
$ExchVer="Exchange2010_SP1"
$service=New-Object Microsoft.Exchange.WebServices.Data.ExchangeService -ArgumentList $ExchVer
$service.Credentials=New-Object Microsoft.Exchange.WebServices.Data.WebCredentials -ArgumentList $user, $pass
$service.Url=$ewsurl
$service.ImpersonatedUserId=New-Object Microsoft.Exchange.WebServices.Data.ImpersonatedUserId `
([Microsoft.Exchange.WebServices.Data.ConnectingIdType]::SMTPAddress,$impdUser);
Write-host "Adding Meeting to Calendar on User:" $impdUser -f Yellow
$Appointment = New-Object Microsoft.Exchange.WebServices.Data.Appointment -ArgumentList $service
$Appointment.Subject = "Test Meeting - Daily Team Meeting - EWS";
$Appointment.Body = "The purpose of this meeting is to discuss status.";
$Appointment.Start = (get-date).adddays($n);
$Appointment.End = $Appointment.Start.AddHours(2);
$Appointment.Location = "Conf Room";
$Appointment.RequiredAttendees.Add("testuser1@testdomain.com");
$Appointment.RequiredAttendees.Add("testuser2@testdomain.com");
$Appointment.OptionalAttendees.Add("testuser3@testdomain.com");
$Appointment.Save()
Write-host "Meeting Added Successfully" -f Green