-
-
Notifications
You must be signed in to change notification settings - Fork 75
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error when executing Get-Email #111
Comments
Hi, we're glad you find our tool helpful! We are aware of the issue around the In the next update, we will add an extra check to skip the email if it's not found in the mailbox, and we will prevent the script from attempting to parse it. And as a fallback, if the email is present but cannot be parsed, it will simply remove the However, it's strange that you can view the emails with Retrieve the email and save the data returned to Make sure to replace Next, save the relevant part of the output to the Now, if you run Additionally, we can check the problematic field and inspect its value: What is returned when you run this? Finally, you can try to parse this value by running: |
Hi there. Thanks for the prompt response! $getMessage = Invoke-MgGraphRequest -Method GET -Uri "https://graph.microsoft.com/v1.0/users/$userIds/messages?filter=internetMessageId eq '$id'" This returned the email content for the same email that I could not download using "Get-Email": $message.receivedDateTime returned the following: [datetime]::Parse($message.receivedDateTime).ToString("yyyyMMdd_HHmmss") returned the following: Thanks |
Hi, Interesting that you're encountering this error, when I manually parse the data, it works without any issues. I'm not sure how to fix this right now and will need to do more testing to see if I can reproduce the problem. As a temporary workaround, you could try modifying the
With this updated block:
This change uses a try block to parse the date. If successful, it creates a date prefix for the filename. If it fails, it sets an empty prefix, ensuring the filename is still valid with just the subject. This way, even if the date parsing fails, you'll still get the full email without errors. In our next update, we'll add more try/catch blocks to help prevent these errors from occurring. I'll also investigate further to see if I can reproduce the issue on my end. Let me know if the temporary solution works for you! |
Hi there. The temporary workaround worked for me, many thanks. Many thanks for your help and prompt responses, much appreciated! |
Hi @Ian-988 , Yeah, this is something we've been dealing with for a while. Initially, we made the messageId the filename, but since multiple users can receive the same message, this caused duplicate filenames. To address this, we started using the subject to make it more readable. However, this also led to duplicates, so we decided to add the received date to the filename as well. Even with this approach, we still encounter duplicates from time to time... In our next update, we'll be adding a prefix to each email we collect, so you'll see filenames like 001, 002, 003-date-subject, and so on. This should eliminate the issue of duplicates once and for all. |
I am trying to download all Emails based on their Message ID using your very useful tool (many thanks)
I have run the following command:
"Get-Email" -userIds sr@ad.com -internetMessageId "<CWL7E2@CWL***.OUTLOOK.COM>"
I get the following error:
[ERROR] An error occurred: Exception calling "Parse" with "1" argument(s): "String was not recognized as a valid DateTime."
If I run the "Show-Email" command with the same parameters the details are returned successfully.
This happens for many Emails (and some are successful for the same user / mailbox)
I can download different emails successfully using the same session.
Any ideas?
Thanks
Ian
The text was updated successfully, but these errors were encountered: