IntuneManagement icon indicating copy to clipboard operation
IntuneManagement copied to clipboard

Documentation related functions cause an exception when calling "Parse" on machines with date format dd/mm/yyyy.

Open illuvtar opened this issue 3 years ago • 10 comments

Documentation related functions cause an exception when calling "Parse" on machines with date format dd/mm/yyyy. or month and day are swapped if day value 12 or below

Error:

Get documentation info for Prod_Win_WindowsUpdates_Broad (Update Policies) MethodInvocationException: Exception calling "Parse" with "1" argument(s): "String '02/15/2022 01:50:53' was not recognized as a valid DateTime." InvalidOperation: You cannot call a method on a null-valued expression. InvalidOperation: You cannot call a method on a null-valued expression.

Code: Documentation.psm1

illuvtar avatar Mar 07 '22 04:03 illuvtar

Hello!

I cannot reproduce this even if I change my date/time format.

createdDateTime, lastModifiedDateTime and modifiedDateTime should be stored in the "2021-08-10T04:42:10.4104838Z" format. I cannot find any object that stores it in '02/15/2022 01:50:53' format as the error states.

How does it look in the detail view? Can you attach the policy that you are trying to document?

Cheers!

Micke-K avatar Mar 07 '22 07:03 Micke-K

I was able to replicate this in a Windows Sandbox using the following:

  1. Get current culture information (sandbox returned en-US for me)
Get-Culture
#LCID             Name             DisplayName
#----             ----             -----------
#1033             en-US            English (United States)
  1. Set culture info to en-NZ (any country with dd/mm/yyyy date format will work)
Set-Culture -CultureInfo en-NZ
  1. Restart powershell
  2. Run .\Start-IntuneManagement.ps1 -ShowConsoleWindow
  3. Document attached json or any config with day created/lastmodified on the 13th or above and check console for Parse errors

I was able to work around the issue with ([DateTime]::Parse(([datetime]$obj.createdDateTime).ToString((get-culture))))

Prod_iOS_Compliance.zip

Hope this helps replicate the issue.

Thanks

illuvtar avatar Mar 07 '22 08:03 illuvtar

I cannot reproduce it no matter what I do.

Can you try this file Documentation.zip ?

Micke-K avatar Mar 07 '22 09:03 Micke-K

Similar errors in the console:

Loading Prod_iOS_Compliance
Get documentation info for Prod_iOS_Compliance (Compliance Policies)
WARNING: Failed to parse date from string 02/15/2022 03:51:28
WARNING: Failed to parse date from string 02/15/2022 03:51:28

Resulting documents now contain Created and Last modified date/time in the format mm/dd/yyyy hh:mm:ss image

microsoftems avatar Mar 07 '22 11:03 microsoftems

That is with the updated psm1. I did a try/catch statement and logged if it failed to parse. I still can understand why the date/time format is completely different from what I get from Graph. Unless something has changed or is different based on where the tenant is.

I found this link where it suggests that it might be a bug somewhere. In .NET?

https://github.com/microsoftgraph/msgraph-sdk-dotnet/issues/79

Micke-K avatar Mar 07 '22 12:03 Micke-K

Can you try this and let me know what it says in the log. Just some more logging

Documentation.zip

Cheers!

Micke-K avatar Mar 07 '22 12:03 Micke-K

Where is the tenant? In the past I've seen different issues depending on where the tenant is. We're a bit different down under ;-)

martincaddick avatar Mar 10 '22 22:03 martincaddick

My tenant us in Australia. I live in Sydney and I do know things are a bit different here :). I used to live in Sweden so I know regional settings can be a big issue. Date conversations has been a problem for a long time.

I still can"t figure out why it returns a different date format for you. I wonder where that happens. If use the same query in Graph Explorer, what do you get then?

Micke-K avatar Mar 10 '22 22:03 Micke-K

Hello!

Looks like this is a PowerShell 6+ issue.

https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/convertfrom-json?view=powershell-7.2#notes

Try starting the script with PowerShell 5 eg add -version 5 to the command line.

Micke-K avatar Mar 17 '22 20:03 Micke-K

Try the new version. It uses -version 5 in the cmd files. Which should force it back to version 5 behaviour.

Let me know how it goes

Micke-K avatar Apr 26 '22 11:04 Micke-K

Closing this. This happens when using PowerShell 6+. Cmd files will always user PowerShell 5.

Cheers!

Micke-K avatar Sep 10 '22 05:09 Micke-K