Summary
Date time fields returned from API calls are subjected to automatic deserialisation by the ConvertFrom-Json cmdlet. These fields are sporadically lost or have the dd MM fields switched due the loss of precision during the deserialisation resulting in inconsistent outputs. I found this in the Get-TeamViewerConnectionReport cmdlet but it stands to reason that all date time fields would be affected
Expected Behavior
Preventing the auto deserialisation of date time fields using the -DateKind string parameter (introduced in PS7.5) in the line return ((Invoke-WebRequest -UseBasicParsing @PSBoundParameters).Content | ConvertFrom-Json -DateKind String) in function Invoke-TeamViewerRestMethod prevents the loss of precision and allows the later call to [DateTime]::Parse($InputString) to correctly output the datetime in the local machine's culture format.
Setps To Reproduce
Describe the steps to reproduce the behavior:
- Call Get-TeamViewerConnectionReport
- Compare output to raw API output call (or non-deserialised call ) to https://webapi.teamviewer.com/api/v1/reports/connections
invoke-TeamViewerPing
True
$count=0
Get-TeamViewerConnectionReport -limit 1000 | %{ $_.enddate ?? ($count++) | out-null ; $_.startdate ?? ($count++) | out-null}
$count
954
$count=0
((Invoke-WebRequest -Uri "https://webapi.teamviewer.com/api/v1/reports/connections" -Method Get -Headers $header -ContentType application/json -ErrorVariable Errrrrrr).Content | Convertfrom-json -DateKind String).records | %{ $_.end_date ?? ($count++) | out-null ; $_.start_date ?? ($count++) | out-null}
$count
8
Reference for deserialisation in ConvertFrom-Json on PS6+
Summary
Date time fields returned from API calls are subjected to automatic deserialisation by the ConvertFrom-Json cmdlet. These fields are sporadically lost or have the dd MM fields switched due the loss of precision during the deserialisation resulting in inconsistent outputs. I found this in the
Get-TeamViewerConnectionReportcmdlet but it stands to reason that all date time fields would be affectedExpected Behavior
Preventing the auto deserialisation of date time fields using the
-DateKind stringparameter (introduced in PS7.5) in the linereturn ((Invoke-WebRequest -UseBasicParsing @PSBoundParameters).Content | ConvertFrom-Json -DateKind String)in functionInvoke-TeamViewerRestMethodprevents the loss of precision and allows the later call to[DateTime]::Parse($InputString)to correctly output the datetime in the local machine's culture format.Setps To Reproduce
Describe the steps to reproduce the behavior:
Reference for deserialisation in ConvertFrom-Json on PS6+