'not able to update to DataTime format using Update-AzTableRow

I have the following powershell script in order to update a value in table storage:

    [string]$filter = `
    [Microsoft.Azure.Cosmos.Table.TableQuery]::GenerateFilterCondition("Query",`
    [Microsoft.Azure.Cosmos.Table.QueryComparisons]::Equal,"(Type = 'FTE')")
    
    $user = Get-AzTableRow `
    -table $cloudTable `
    -customFilter $filter

    # Change the entity.
    $user.LastRunTime = "2022-04-24T01:09:30.4224457Z"

    $user | Update-AzTableRow -table $cloudTable

With this update, I see LastRunTime in 'String' format. How do I update this to 'DateTime' format.



Solution 1:[1]

It's a string because what you're setting it to is a string. You should set it to a DateTimeOffset.

$user.LastRunTime = [System.DateTimeOffset]"2022-04-24T01:09:30.4224457Z"

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 joelforsyth