-
Notifications
You must be signed in to change notification settings - Fork 141
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
ADSRootKey: Fails with 'String was not recognized as a valid DateTime' exception #702
Comments
This is most likely trying to return the value from DateTime to a string. Since the parameter
Because Get-TargetResource returns EffectiveTime as string (need by the schema, and done by line 110 above) the line at 423 seems to try to convert the value back to DateTime. Line 422 and 423 prepares the values as DateTime so the comparison compares two DateTime values (instead of comparing strings). ActiveDirectoryDsc/source/DSCResources/MSFT_ADKDSKey/MSFT_ADKDSKey.psm1 Lines 422 to 423 in b89e4f0
The problem seems to be that the parsing should always be done through a known format, that works regardless of locale. 🤔 |
Maybe line 110 should be changed to something like this, assuming the property EffectiveTime is a DateTime in all supported OS: $targetResource['EffectiveTime'] = $kdsRootKey.EffectiveTime.ToString('yyyy-MM-dd HH:mm:ss.fff') or $targetResource['EffectiveTime'] = $kdsRootKey.EffectiveTime.GetDateTimeFormats('o') |
On your last point, the property EffectiveTime appears to be a DateTime on Windows Server 2012 R2 and Windows Server 2022 - doubt it's changed between?
|
OK so there's a load of weirdness going on when DateTime attempts to process dates in non-US cultures, in what I'm pretty sure is buggy behaviour (see my report at https://stackoverflow.com/questions/77968235/how-is-powershell-datetimeparse-processing-broken-in-certain-locales) But it looks like all that's needed to fix it here is to bypass the unnecessary Parse() call - have tested the attached PR on my system & seems to work perfecly now. |
Problem description
Trying to use KDSRootKey to validate an existing KDSRootKey on a server with the English (United Kingdom) locale set.
Receiving this error:
Verbose logs
DSC configuration
Suggested solution
Having stepped through the code in MSFT_ADKDSKey.psm1 it looks like this is failing in Get-TargetResource, line 110. If I run these commands on my system:
I get:
Running '$kdsRootKey.EffectiveTime' returns the value '01 February 2024 12:21:51', but this is not accepted by [DateTime]::Parse() - possibly down to system locale (which is en-GB)? To be honest I'm not sure why we are running [DateTime]::Parse() on $kdsRootKey.EffectiveTime in line 110 or line 423 anyway, as it's already a [DateTime] object, so this could be a fix?
Operating system the target node is running
PowerShell version and build the target node is running
ActiveDirectoryDsc version
The text was updated successfully, but these errors were encountered: