01 Apr

Uploading a file to Azure Blob Storage

azure Think of the following scenario:
You have an application running on Microsoft Azure, and you have a continuous deployment application enabled to help updating your application. It might be that some applications can’t get your local files, and that will prove to be quite the pain. A nice solution that you have there is using Azure Blob Storage. You can easily put a file there, copy the link to that file, and use that in your continuous deployment.

 Below, you will find a small and very basic PowerShell script, that will enable you to upload a single file to Azure Blob Storage:

 

Prerequisites:

  • Azure Storage Account
  • Azure Storage Blob
  • Azure Storage Container
  • Subscription name and ID


$SubscriptionName = ""
$SubscriptionId = ""
$DestContainer = ""
$StorageAccountName = ""
Import-AzurePublishSettingsFile -PublishSettingsFile ""
Set-AzureSubscription -SubscriptionId $SubscriptionId -CurrentStorageAccountName $StorageAccountName
Select-AzureSubscription -SubscriptionName $SubscriptionName

Set-AzureStorageBlobContent -File "" -Container $DestContainer

As you can see, there is very little to it.
The “Import-AzurePublishSettingsFile” give the largest part of the stored Azure credentials.
Set-AzureSubscription configures and stores common Windows Azure subscription settings.
Select-AzureSubscription selects or clears a Windows Azure subscription to be used as the current subscription.

If you want to make sure that the Subscription is removed from PowerShell afterwards, you can put “Remove-AzureSubscription -SubscriptionName “The name of the subscription” ” at the end of the script.




Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.