Skip to content

Instantly share code, notes, and snippets.

@pkirch
Last active August 29, 2015 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pkirch/7e6049c61e18672ee52b to your computer and use it in GitHub Desktop.
Save pkirch/7e6049c61e18672ee52b to your computer and use it in GitHub Desktop.
Upload a VHD to Azure Storage Blob via PowerShell.
# Get administration certificate.
# Get-AzurePublishSettingsFile
# Import-AzurePublishSettingsFile -PublishSettingsFile "C:\Users\pkirch\Downloads\Azure MSDN - pkirchner-9-11-2014-credentials.publishsettings"
# Settings
$SubscriptionName = "Azure MSDN - pkirchner"
$StorageAccountName = "pkmsft"
$Container = "vhds"
$LocalVhd = "C:\Users\pkirch\fixedvhd20mb.vhd"
# Select my Microsoft Azure Subscription.
Select-AzureSubscription -SubscriptionName $SubscriptionName
# Get locations. Need to know one for storage account creation.
# Get-AzureLocation | Select -Property DisplayName
# Create new storage account.
New-AzureStorageAccount -Location "West Europe" -StorageAccountName $StorageAccountName -Type Standard_LRS
# Create container for VHDs.
$StorageAccountKey = Get-AzureStorageKey -StorageAccountName $StorageAccountName
New-AzureStorageContext -StorageAccountKey $StorageAccountKey.Primary -StorageAccountName $StorageAccountName | `
New-AzureStorageContainer -Name $Container -Permission Off
# Add-AzureVhd needs the CurrentStorageAccountName to be set.
Set-AzureSubscription -SubscriptionName $SubscriptionName -CurrentStorageAccountName $StorageAccountName
# Build destination path automatically.
$NewContainer = Get-AzureStorageContainer -Name $Container
$VhdFile = Split-Path -Path $LocalVhd -Leaf
$Destination = $NewContainer.CloudBlobContainer.Uri.AbsoluteUri + "/" + $VhdFile
$Destination
# Upload VHD
Add-AzureVhd -Destination $Destination -LocalFilePath $LocalVhd
## Clean Up ##
# Delete storage account.
# Remove-AzureStorageAccount -StorageAccountName $StorageAccountName
########################################################################
# THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF #
# ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO #
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A #
# PARTICULAR PURPOSE. #
########################################################################
@pkirch
Copy link
Author

pkirch commented Jan 2, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment