You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Export history to a csv file with Get-History | Export-Csv -path $logfile -encoding unicode -NoTypeInformation
Import the last item of the history with $histitem = Import-Csv -Path $logfile | Select-Object -last 1
Load the item into the the history with $histitem | Add-History
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.
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
Prerequisites
Steps to reproduce
On a machine where the date format is not US
Get-History | Export-Csv -path $logfile -encoding unicode -NoTypeInformation$histitem = Import-Csv -Path $logfile | Select-Object -last 1$histitem | Add-History$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.$histitem | Add-HistoryExpected behavior
Actual behavior
Error details
Environment data
Visuals
No response