0

I have a BlobTrigger azure function on Powershell. I am trying get the blob uri in order to create a managed disk out of this vhd blob with the below scipt:

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

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

From the cloud shell, i can get the uri with code below:

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

But with Azure Functions, i cannot. My AF code is below:

# 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 returns empty. I have checked blob documentation , but couldn't find any solutions.

Do you have any suggestions?

3
  • $InputBlob already contains the data from the blob as a byte array. Are you sure you need the URI? Commented Aug 28, 2020 at 21:55
  • I have added to the question my script which creates a NewAzDisk. There, i need the blob uri for -SourceUri parameter. I don't know how to create a NewAzDisk by using a byte array with Powershell Commented Aug 29, 2020 at 9:43
  • 1
    $TriggerMetadata.Uri should give you the URI Commented Aug 30, 2020 at 2:19

1 Answer 1

2

You can try $TriggerMetadata.Name to get the name, or $TriggerMetadata.Uri as suggested by @Anatoli Beliaev.

As an alternative, you can try something like this (untested):

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

This works in .NET at least, and the documentation looks like it might behave similarly.

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)
Sign up to request clarification or add additional context in comments.

3 Comments

[string] $myBlob will still give you the same content of the blob, just converted to a string.
Ah, obviously it does, I somehow got confused. Thanks for the info, I changed the answer.
@AlexAIT I am using $TriggerMetaData.Name to get Name of blob but it happens to be empty. Please let me know quick fix if possible. Otherwise i'll post different thread for the same.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.