Exchange Web Services (EWS)

Roger Roger 6,041 Reputation points
2024-10-01T05:32:50.5866667+00:00

Hi all,

I have the script below that was working fine but recently stopped functioning. I am unsure if this is due to the deprecation of basic authentication or because Exchange Web Services (EWS) is no longer supported as it's a legacy client. The purpose of the script is to forward calendar invites to newly joined employees. Is there any other way to achieve this? Please guide me.(i am not using password in plain text like the below, i have encrypted it. just for understanding i have put password)


Start-Transcript -Path "C:\temp\transcript.txt"
$OU = "contoso.com/OU1"
$CSV = ".\userlist.csv"
$Users = Import-Csv '.\userlist.csv'
$MBX = '[email protected]'
$Items = 50
$DaysInTheFuture = 300
$Now = [System.DateTime]::Now
$Then = [System.DateTime]::Now.AddDays($DaysInTheFuture)
$username = "[email protected]"
$password = "somepwd"
$TenantPass = $password | ConvertTo-SecureString -AsPlainText -Force
$EWSServicePath = 'C:\Program Files\Microsoft\Exchange\Web Services\2.2\Microsoft.Exchange.WebServices.dll'
Import-Module $EWSServicePath
$Service = New-Object Microsoft.Exchange.WebServices.Data.ExchangeService
$ExchVer = [Microsoft.Exchange.WebServices.Data.ExchangeVersion]::Exchange2010_SP1
$Service = New-Object Microsoft.Exchange.WebServices.Data.ExchangeService($exchver)
$Credentials = New-Object System.Net.NetworkCredential($username, $password)
$service.Credentials = $Credentials
 
#Setting up EWS URL
$EWSurl = "https://outlook.office365.com/EWS/Exchange.asmx"
$Service.URL = $EWSurl
$service.ImpersonatedUserId = New-Object Microsoft.Exchange.WebServices.Data.ImpersonatedUserId ([Microsoft.Exchange.WebServices.Data.ConnectingIdType]::SMTPAddress,$MBX);
 
$folderid = new-object Microsoft.Exchange.WebServices.Data.FolderId([Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::Calendar,$MailboxToImpersonate)
$calendarFolder = [Microsoft.Exchange.WebServices.Data.CalendarFolder]::Bind($service,$folderid)
$calendarView = new-object Microsoft.Exchange.WebServices.Data.CalendarView($Now, $Then)
$calendarView.MaxItemsReturned = $Items;
$calendarView.PropertySet = new-object Microsoft.Exchange.WebServices.Data.PropertySet([Microsoft.Exchange.WebServices.Data.BasePropertySet]::FirstClassProperties)
$findItemResults = $calendarFolder.FindAppointments($calendarView)
if ($findItemResults) {
   $FutureMeetings = @()
   Foreach ($CalItem in $findItemResults) {
      If ($CalItem.IsMeeting -eq $True) {$FutureMeetings += $CalItem}
   }
   if ($FutureMeetings) {
        $emaillist = @()
      foreach ($user in $Users) {
         $EmpType = $null
         $EmpType = get-qaduser $user.UserPrincipalName -properties employeeType | select employeeType
            If (($user.RecipientTypeDetails -eq 'UserMailbox')) { $emaillist += $user.emailaddress }
         }
      if ($emaillist.count -gt 0) {
         foreach ($item in $FutureMeetings) {
            [void]$item.Forward("shared meeting invite with you.",$emaillist)
            ("Date: "+$Now) | out-file ".\fwreport.csv" -append
            ("Addresses: "+$emaillist) | out-file ".\fwreport.csv" -append
            ("Subject: "+$item.Subject) | out-file ".\fwreport.csv" -append
            ("Start: "+$item.Start) | out-file ".\fwreport.csv" -append
            ("End: "+$item.End) | out-file ".\fwreport.csv" -append
            ("Location: "+$item.Location) | out-file ".\fwreport.csv" -append
            ("--------------------------------------------------------------") | out-file ".\fwreport.csv" -append
         }
      }
   }
}
Stop-Transcript

Microsoft Exchange Online
Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
11,989 questions
Microsoft Exchange Online Management
Microsoft Exchange Online Management
Microsoft Exchange Online: A Microsoft email and calendaring hosted service.Management: The act or process of organizing, handling, directing or controlling something.
4,515 questions
Exchange Server Management
Exchange Server Management
Exchange Server: A family of Microsoft client/server messaging and collaboration software.Management: The act or process of organizing, handling, directing or controlling something.
7,625 questions
Microsoft Exchange Hybrid Management
Microsoft Exchange Hybrid Management
Microsoft Exchange: Microsoft messaging and collaboration software.Hybrid Management: Organizing, handling, directing or controlling hybrid deployments.
2,093 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Roger Roger 6,041 Reputation points
    2024-10-01T09:27:53.36+00:00

    Added Graph tag

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.