Quick Script: ARM – Upload VHD

Here is a quick script to create a new resource group, Storage account, storage account container and upload a VHD

 

Switch-AzureMode AzureResourceManager

$ResourceGroupNames = @('RG0','RG1')

foreach($ResourceGroupName in $ResourceGroupNames)
{
$location = 'North Central US'
$StorageAccountName = "sa01"
$StorageType = 'Standard_LRS'
$storageContainer = 'VHDImages'
$StorageAccountName = $StorageAccountName.ToLower()
$storageContainer = $storageContainer.tolower()
New-AzureResourceGroup -Name $ResourceGroupName -Location $location
New-AzureStorageAccount -ResourceGroupName $ResourceGroupName -AccountName $StorageAccountName -Type $StorageType -Location $location
$storageKey = Get-AzureStorageAccountKey -ResourceGroupName $ResourceGroupName -AccountName $StorageAccountName
$StorageContext = New-AzureStorageContext -StorageAccountName $StorageAccountName -StorageAccountKey $storageKey.Key1
New-AzureStorageContainer -Context $StorageContext -Name $storageContainer -Permission Off
Add-AzureVhd -LocalFilePath C:\Users\rplank\Downloads\rhel6-x64-template-azure.vhd -Destination "https://$StorageAccountName.blob.core.windows.net/vhdimages/rhel6-x64-template-azure.vhd" -ResourceGroupName $ResourceGroupName
}

 

Leave a Reply

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