Skip to content

Issue with new DateTimeOffset::Parse logic in Test-AccessToken (and others) #210

@thedivinehairband

Description

@thedivinehairband

When using the 1.5.0 version of the code the new logic to check the bearer token expiry in Test-AccessToken is returning an error:

Test-AccessToken : Exception calling "Parse" with "3" argument(s): "String was not recognized as a valid DateTime." At C:\Users\<USERNAME>\Documents\WindowsPowerShell\Modules\IntuneWin32App\1.5.0\Private\Invoke-MSGraphOperation.ps1:110 char:19 if (-not (Test-AccessToken)) { ~~~~~~~~~~~~~~~~ CategoryInfo : NotSpecified: (:) [Test-AccessToken], MethodInvocationException FullyQualifiedErrorId : FormatException,Test-AccessToken

The line in question is:

$ExpiresOnUTC = [DateTimeOffset]::Parse($Global:AccessToken.ExpiresOn.ToString(), [System.Globalization.CultureInfo]::InvariantCulture, System.Globalization.DateTimeStyles]::AssumeUniversal).ToUniversalTime()

Seems to have an issue with the first arguement

Changing it to the below:
$ExpiresOnUTC = [DateTimeOffset]::Parse($Global:AccessToken.ExpiresOn.ToString()).ToUniversalTime()

Seems to fix the issue, but my knowledge is lacking to be able to tell if this is a good fix or a bodge fix.

Similar logic is found in the Invoke-AzureStorageBlobUpload function and possibly others. Has failed under PowerShell 5 on both Server 2016 and Windows 11 based machines running on UK time format.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions