Mandar Jogalekar
Mandar Jogalekar

Reputation: 3281

Get Azure storage blob url after uploading powershell

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?

Upvotes: 6

Views: 8980

Answers (2)

egnomerator
egnomerator

Reputation: 1115

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

Upvotes: 4

Martin Brandl
Martin Brandl

Reputation: 59001

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

(Get-AzureStorageBlob -blob 'StarterSite.zip' -Container 'clouddata ').ICloudBlob.uri.AbsoluteUri

Upvotes: 9

Related Questions