skip to Main Content

I am building a timer-triggered Azure Function that uses a PowerShell script. For input binding, there is Azure Table Storage. In order to use newly added values in my script, I was hoping to make use of the automatic Timestamp value that gets generated on each value addition to the table. However, the Timestamp is rendered empty when I run the function. The values are present in the table though.

My test code –

# Input bindings are passed in via param block.
param($Timer, $inputTable)

$newValues = $inputTable.GetEnumerator()
$newValues | ForEach-Object {
    Write-host $_.Timestamp
}

Output when Write-host $_.Timestamp

2022-06-17T07:16:55.538 [Information] OUTPUT:
2022-06-17T07:16:55.614 [Information] INFORMATION:
2022-06-17T07:16:55.616 [Information] INFORMATION:
2022-06-17T07:16:55.621 [Information] INFORMATION:

Output for any other value Eg. Write-host $_.PartitionKey

2022-06-17T07:17:34.230 [Information] OUTPUT:
2022-06-17T07:17:34.310 [Information] INFORMATION: partition1
2022-06-17T07:17:34.312 [Information] INFORMATION: partition1
2022-06-17T07:17:34.318 [Information] INFORMATION: partition1

2

Answers


  1. If you are using the Get-AzTableRow in your azure function, you will not give the time stamp.

    The Get-AzTableRow will return the table columns and Partition and RowKey.

    If you are trying to get the timestamp you have to convert that into string. likes below

    Type - 1
    [String]$_.Timestamp
    
    # or 
    Type - 2
    $_.Timestamp.toString("s")
    

    I have added the same thing in your code.

    $newValues | ForEach-Object {
        Write-host $_.Timestamp.toString("s")
    }
    
    Login or Signup to reply.
  2. If you’re using the Table Storage input binding then I don’t think the TimeStamp is present in the returned data.

    Example

    I have a function which has HTTP Input Binding and Table Storage Input Binding to lookup a list of users for table storage when invoked.

    Table Storage

    enter image description here

    function.json

    {
      "bindings": [
        {
          "authLevel": "function",
          "type": "httpTrigger",
          "direction": "in",
          "name": "Request",
          "methods": [
            "get"
          ],
          "route": "get/user"
        },
        {
          "name": "PersonEntity",
          "type": "table",
          "tableName": "users",
          "connection": "MyStorageConnectionAppSetting",
          "direction": "in"
        },
        {
          "type": "http",
          "direction": "out",
          "name": "Response"
        }
      ]
    }
    

    run.ps1

    When I trigger the function it returns all users but the TimeStamp property is not returned from table storage. I don’t think there’s a way to retrieve this using the input binding.

    Debugging Output

    enter image description here

    Also looks like someone logged an issue here:

    https://github.com/Azure/azure-functions-nodejs-worker/issues/320

    And this is the same as with Python and NodeJs bindings so not unique to PowerShell.

    You could use the AzTable module that was linked in the other answer or there is another module (AzBobbyTables) in the PowerShell Gallery which is newer and written in C# and is supposed to be much more performant:

    https://www.powershellgallery.com/packages/AzBobbyTables/2.0.0

    https://twitter.com/PalmEmanuel/status/1462818044959461382

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search