我正在構建一個使用 PowerShell 腳本的計時器觸發 Azure 函式。對于輸入系結,有 Azure 表存盤。為了在我的腳本中使用新添加的值,我希望利用Timestamp在表中添加每個值時生成的自動值。但是,當我運行該函式時,時間戳變為空。這些值存在于表中。
我的測驗代碼 -
# Input bindings are passed in via param block.
param($Timer, $inputTable)
$newValues = $inputTable.GetEnumerator()
$newValues | ForEach-Object {
Write-host $_.Timestamp
}
輸出時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:
任何其他值的輸出,例如。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
uj5u.com熱心網友回復:
如果您使用的是表存盤輸入系結,那么我認為回傳的資料中不存在時間戳。
例子
我有一個函式,它具有 HTTP 輸入系結和表存盤輸入系結,用于在呼叫時查找用戶串列以進行表存盤。
表存盤

函式.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"
}
]
}
運行.ps1
當我觸發該函式時,它會回傳所有用戶,但不會從表存盤中回傳 TimeStamp 屬性。我認為沒有辦法使用輸入系結來檢索它。
除錯輸出

看起來有人在這里記錄了一個問題:
https://github.com/Azure/azure-functions-nodejs-worker/issues/320
這與 Python 和 NodeJs 系結相同,因此不是 PowerShell 獨有的。
您可以使用在另一個答案中鏈接的 AzTable 模塊,或者在 PowerShell 庫中有另一個模塊(AzBobbyTables),它更新并用 C# 撰寫,并且應該具有更高的性能:
https://www.powershellgallery.com/packages/AzBobbyTables/2.0.0
https://twitter.com/PalmEmanuel/status/1462818044959461382
uj5u.com熱心網友回復:
如果您在 azure 函式中使用Get-AzTableRow,則不會給出時間戳。
Get-AzTableRow將回傳表列以及Partition和RowKey。
如果您嘗試獲取時間戳,則必須將其轉換為string。喜歡下面
Type - 1
[String]$_.Timestamp
# or
Type - 2
$_.Timestamp.toString("s")
我在您的代碼中添加了相同的內容。
$newValues | ForEach-Object {
Write-host $_.Timestamp.toString("s")
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/493250.html
上一篇:以概率在矩陣中翻轉一點
