Azure Functions PowerShell - 从 Azure 存储表访问时间戳值

标签 azure powershell azure-functions azure-table-storage

我正在构建一个使用 PowerShell 脚本的计时器触发的 Azure 函数。对于输入绑定(bind),有 Azure 表存储。为了在我的脚本中使用新添加的值,我希望利用在表中添加每个值时生成的自动时间戳值。但是,当我运行该函数时,时间戳呈现为空。不过,这些值已显示在表中。

我的测试代码 -

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

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

写入主机$_.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:

输出任何其他值,例如。 写入主机$_.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

最佳答案

如果您使用表存储输入绑定(bind),那么我认为返回的数据中不存在时间戳。

示例

我有一个具有 HTTP 输入绑定(bind)和表存储输入绑定(bind)的函数,用于在调用时查找表存储的用户列表。

表存储

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

当我触发该函数时,它会返回所有用户,但 TimeStamp 属性不会从表存储中返回。我认为没有办法使用输入绑定(bind)来检索它。

调试输出

enter image description here

看起来也有人在这里记录了一个问题:

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

这与 Python 和 NodeJs 绑定(bind)相同,因此并非 PowerShell 所独有。

您可以使用其他答案中链接的 AzTable 模块,或者 PowerShell 库中还有另一个模块 (AzBobbyTables),该模块较新,用 C# 编写,应该具有更高的性能:

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

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

关于Azure Functions PowerShell - 从 Azure 存储表访问时间戳值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72655950/

相关文章:

.net - 基于声明的 wcf 服务出错 - 无法验证传入策略

postgresql - 从数据工厂读取 Postgress(以 SQL_ASCII 编码)

c# - 重命名文件Powershell看不到

windows - 如何将目录更改为路径中的特定文件夹?

c# - Azure Functions System.Net.Primitives : Value cannot be null.(参数 'host' )

Azure B2C 设置

azure - 如何将 Azure VM 重启和关闭日志获取到 Azure Log Analytics?

windows - 如何在 Windows 上的 powershell 上执行 sudo

Azure函数不会早于设置值超时

azure - 为 Azure 部署管道中的暂存槽添加启动和停止任务