我正在构建一个使用 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)的函数,用于在调用时查找表存储的用户列表。
表存储
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)来检索它。
调试输出
看起来也有人在这里记录了一个问题:
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
关于Azure Functions PowerShell - 从 Azure 存储表访问时间戳值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72655950/