Feb 03 2019 05:33 PM
Hi,
We have email account and users daily send emails with attachments to that email account and automated powershell script was running on the windows server to retrieve data from email attachments . Script was working fine but now we are getting authentication token issue since our Outlook was migrated to Office 365.
May I know your suggestions to resolve the issue?
I am totally new to azure Office 365 and Azure.
Thank you,
AA
Feb 03 2019 10:38 PM
Feb 04 2019 06:49 AM
Thank you for your comments but my problem is, I do not have access for admin site and I am not sure what kind of information I should get from admin team.
Feb 04 2019 09:29 AM
Without seeing the actual script, we can only guess what's going on. My guess would be that the script is using EWS impersonation, as you cannot access item-level details with "regular" PowerShell. Thus you most likely need to add the impersonation permissions on the migrated account. But that's just a guess, best talk with the author of the script.
Feb 06 2019 01:56 PM
Hi Vasil,
Here is my script, it is working fine but I want to use Date Range instead of ArgumentList in FindItems method (highlighted in script). May I know which property I should use for Date Range in FindItems?
$mail="xxxx@xxxx.xxx"
$password="xxxxxx"
# Set the path to your copy of EWS Managed API
$dllpath = "C:\Program Files\Microsoft\Exchange\Web Services\2.2\Microsoft.Exchange.WebServices.dll"
# Load the Assembly
[void][Reflection.Assembly]::LoadFile($dllpath)
# Create a new Exchange service object
$service = new-object Microsoft.Exchange.WebServices.Data.ExchangeService
#These are your O365 credentials
$Service.Credentials = New-Object Microsoft.Exchange.WebServices.Data.WebCredentials($mail,$password)
# this TestUrlCallback is purely a security check
$TestUrlCallback = {
param ([string] $url)
if ($url -eq "https://autodiscover-s.outlook.com/autodiscover/autodiscover.xml") {$true} else {$false}
}
# Autodiscover using the mail address set above
$service.AutodiscoverUrl($mail,$TestUrlCallback)
$results = $service.FindItems(
"Inbox",
( New-Object Microsoft.Exchange.WebServices.Data.ItemView -ArgumentList 20)
)
$MailItems = $results.Items | where hasattachments
foreach ($MailItem in $MailItems){
$MailItem.Load()
foreach($Attachment in $MailItem.Attachments){
$Attachment.Load()
$File = new-object System.IO.FileStream(("C:\Temp\Attachments\" + $Attachment.Name.ToString()),[System.IO.FileMode]::Create)
$File.Write($attachment.Content, 0, $attachment.Content.Length)
$File.Close()
}
}
Thank you,
AA
Feb 06 2019 11:01 PM
You will have to use a Search filter for that: https://docs.microsoft.com/en-us/exchange/client-developer/exchange-web-services/how-to-use-search-f...
Feb 07 2019 07:12 AM
Thank you Vasil. I used search filter to get Date Range results.
Mar 13 2020 08:34 AM
I used search filter to get Date Range results.
Would you mind to share the piece of code you used for the search filter based on date?
Thanks.
Feb 07 2022 06:52 AM