Skip to content

Add-History date behaviour changed from 7.1 to 7.2 - now requires least significant centred format.  #15949

@jhoneill

Description

@jhoneill

Prerequisites

Steps to reproduce

On a machine where the date format is not US

  1. Export history to a csv file with Get-History | Export-Csv -path $logfile -encoding unicode -NoTypeInformation
  2. Import the last item of the history with $histitem = Import-Csv -Path $logfile | Select-Object -last 1
  3. Load the item into the the history with $histitem | Add-History
  4. Change to US date format, with $histitem.EndExecutionTime = "08/18/2021 16:43:50"; $histitem.StartExecutionTime = "08/18/2021 16:43:50" - note that the imported fields are strings, not [datetime] objects.
  5. Import the modified item with $histitem | Add-History

Expected behavior

On a non-US machine the import at step 3 works , and the import at step 5 generates the message 
"Add-History: Cannot add history because the input object has a format that is not valid."

Actual behavior

On Windows PowerShell, PowerShell Core 6.x and Powershell 7 and 7.1 the local date format succeeds and US date format fails. 
On PowerShell 7.2 preview 8 Local date format fails and only US format succeeds.

Error details

�[92mException             : �[0m
    �[92mType    : �[0mSystem.IO.InvalidDataException
    �[92mMessage : �[0m�[31;1mCannot add history because the input object has a format that is not valid.
    �[92mHResult : �[0m-2146233087
�[92mTargetObject          : �[0m@{Id=520; CommandLine=$histitem | Add-History; ExecutionStatus=Completed; StartExecutionTime=18/08/2021 18:00:35; EndExecutionTime=18/08/2021 18:00:35; Duration=00:00:00.0826743}
�[92mCategoryInfo          : �[0mInvalidData: (@{Id=520; CommandLiÔǪn=00:00:00.0826743}:PSObject) [Add-History], InvalidDataException
�[92mFullyQualifiedErrorId : �[0mAddHistoryInvalidInput,Microsoft.PowerShell.Commands.AddHistoryCommand
�[92mInvocationInfo        : �[0m
    �[92mMyCommand        : �[0mAdd-History
    �[92mScriptLineNumber : �[0m1
    �[92mOffsetInLine     : �[0m13
    �[92mHistoryId        : �[0m105
    �[92mLine             : �[0m$histitem | Add-History
    �[92mPositionMessage  : �[0mAt line:1 char:13
                       + $histitem | Add-History
                       +             �[31;1m~~~~~~~~~~~
    �[92mInvocationName   : �[0mAdd-History
    �[92mCommandOrigin    : �[0mInternal
�[92mScriptStackTrace      : �[0mat <ScriptBlock>, <No file>: line 1
�[92mPipelineIterationInfo : �[0m

Environment data

�[32;1mName                           Value�[0m
�[32;1m----                           -----�[0m
PSVersion                      7.2.0-preview.8
PSEdition                      Core
GitCommitId                    7.2.0-preview.8
OS                             Microsoft Windows 10.0.19043
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Visuals

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-BugIssue has been identified as a bug in the productResolution-FixedThe issue is fixed.WG-Cmdlets-Corecmdlets in the Microsoft.PowerShell.Core module

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions