I had an exchange script running that has this code at the beginning:
##Exchange Service
$service = New-Object Microsoft.Exchange.WebServices.Data.ExchangeService([Microsoft.Exchange.WebServices.Data.ExchangeVersion]::Exchange2016)
$service.Url = new-object Uri("https://outlook.office365.com/EWS/Exchange.asmx");
$service.Credentials = New-Object Microsoft.Exchange.WebServices.Data.WebCredentials($MailboxName,$passwd)
##Target Folder Binding
$folderid = new-object Microsoft.Exchange.WebServices.Data.FolderId([Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::Inbox,$targetMailboxName)
$InboxFolder = [Microsoft.Exchange.WebServices.Data.Folder]::Bind($service,$folderid)
This code did work in the past but now I get an 401 unauthorized error message when trying to connect to the exchange server.
The strange thing is, I tryed to verify my authorization here and after the test every checkmark is green.
So my account is authorized but still can't access the information when running it via powershell code.
Any idea what I could try to solve this problem?