Last active
August 29, 2015 14:06
-
-
Save pkirch/7e6049c61e18672ee52b to your computer and use it in GitHub Desktop.
Upload a VHD to Azure Storage Blob via PowerShell.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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. # | |
######################################################################## |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I use this Gist in my blog post on http://blogs.msdn.com/b/pkirchner/archive/2014/09/12/beispielcode-vhd-in-azure-storage-blob-via-powershell-hochladen.aspx.