azure - 如何使用 Powershell 从 Azure Functions 获取 Azure Blob URI?

标签 azure powershell azure-functions azure-blob-storage

我在 Powershell 上有一个 BlobTrigger azure 函数。我正在尝试获取blob uri,以便使用以下脚本从此 vhd blob 创建托管磁盘:

$diskConfig = New-AzDiskConfig -AccountType $storageType -Location $location -CreateOption Import -StorageAccountId $storageAccountId -SourceUri $sourceVHDURI

New-AzDisk -Disk $diskConfig -ResourceGroupName $resourceGroupName -DiskName $diskName

从云 shell 中,我可以使用以下代码获取 uri:

$(Get-AzureStorageBlob -Blob myblob -Container 'mycontainer' -Context $StorageContext).ICloudBlob.uri.AbsoluteUri

但是使用 Azure Functions,我不能。我的 AF 代码如下:

# Input bindings are passed in via param block.
param([byte[]] $InputBlob, $TriggerMetadata)

# Write out the blob name and size to the information log.
Write-Host "PowerShell Blob trigger function Processed blob! Uri: $($InputBlob.ICloudBlob.uri.AbsoluteUri)"

$InputBlob.ICloudBlob.uri.AbsoluteUri 返回空。我查过blob documentation ,但找不到任何解决方案。

你有什么建议吗?

最佳答案

您可以尝试 $TriggerMetadata.Name 获取名称,或按照 @Anatoli Beliaev 的建议尝试 $TriggerMetadata.Uri

作为替代方案,您可以尝试这样的操作(未经测试):

param([Microsoft.Azure.Storage.Blob.ICloudBlob] $myBlob)

这至少在 .NET 中有效,并且文档看起来它的行为可能类似。

https://learn.microsoft.com/en-us/azure/azure-functions/functions-reference-powershell?tabs=portal#type-casting-for-triggers-and-bindings

For certain bindings like the blob binding, you're able to specify the type of the parameter.

For example, to have data from Blob storage supplied as a string, add the following type cast to my param block:

param([string] $myBlob)

关于azure - 如何使用 Powershell 从 Azure Functions 获取 Azure Blob URI?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63637360/

相关文章:

Azure Runbook 重命名 SQL 数据库

azure - Web App后台任务的暂存槽处理消息

Azure Blob 存储触发器函数未触发

azure - .Net Core 2.0 - Azure Active Directory - NGinX 反向代理 - HTTPS

powershell - 如何使用 Powershell 脚本在 Windows 10 中更改语言/区域和语音

c# - 使用 Azure Active Directory 身份验证而不重定向到 Microsoft

powershell - 如何在 PowerShell 中将 UInt32 转换为(负)Int32?

javascript - Azure Function - Node 应用程序中的端口耗尽

azure - 无法解析名为 'SecurityEvent' 的表或列表达式

c# - Xamarin MySQLite - 无法从本地存储加载错误