Get Azure storage blob url after uploading powershell
Asked Answered
R

2

6

How can i get url of the blob i just uploaded using powershell.My code currently is

$storagekey=Get-AzureStorageKey -StorageAccountName appstorageacc
$ctx=New-AzureStorageContext -StorageAccountName 
appstorageacc -   StorageAccountKey $storagekey.Primary
Set-AzureStorageBlobContent -File C:\Package\StarterSite.zip 
-Container   clouddata -Context $ctx -Force

Blob is uploaded successfully, but how can i get it's url out?

Roxie answered 12/11, 2015 at 9:45 Comment(0)
R
9

Retrieve blob information using the Get-AzureStorageBlob cmdlet and select the AbsoluteUri:

(Get-AzureStorageBlob -blob 'StarterSite.zip' -Container 'clouddata ').ICloudBlob.uri.AbsoluteUri
Rocray answered 12/11, 2015 at 10:33 Comment(2)
How did you find this? Looking at the object/properties returned from Get-AzureStorageBlob, I had no indication there was more info available.Snipes
@Snipes At the bottom in the documentation (learn.microsoft.com/en-us/powershell/module/azure.storage/…) you see the output of the cmdletRocray
S
4

Another option: just capture the result of Set-AzureStorageBlobContent

$result = Set-AzureStorageBlobContent -File C:\Package\StarterSite.zip
$blobUri = $result.ICloudBlob.Uri.AbsoluteUri

It's not necessary to call Get-AzureStorageBlob after calling Set-AzureStorageBlobContent.

Set-AzureStorageBlobContent returns the same object type that Get-AzureStorageBlob returns.

More details

The output type is AzureStorageBlob for both Get-AzureStorageBlob and Set-AzureStorageBlobContent

AzureStorageBlob has a ICloudBlob property

AzureStorageBlob.ICloudBlob getter returns a CloudBlob which has the Uri property

Samhita answered 26/3, 2020 at 18:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.