Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
This sample creates a new cloud service, storage account and VM.
# Sample by Peter Kirchner (peter.kirchner@microsoft.com)
# Settings
$subscriptionName = "MSFT MVA Live" # Get-AzureSubscription
$location = "West Europe" # Get-AzureLocation
$serviceName = "pktestservice"
$storageAccountName = "pkteststorage"
$storageContainerName = "vhds"
$adminUsername = "adm_test"
$adminPassword = "Azureisttoll!"
$imageNameWS2012R2 = "a699494373c04fc0bc8f2bb1389d6106__Windows-Server-2012-R2-201410.01-en.us-127GB.vhd" # Get-AzureVMImage
$vmName = "host1"
# In case you have more than one Azure subscription, select one.
Select-AzureSubscription -SubscriptionName $subscriptionName
# 1st: create cloud service
New-AzureService -Location $location -ServiceName $serviceName
# 2nd: create storage account.
New-AzureStorageAccount -Location $location -StorageAccountName $storageAccountName
# 3rd: create container for VHDs.
$storageAccountKey = Get-AzureStorageKey -StorageAccountName $storageAccountName
$storageContext = New-AzureStorageContext -StorageAccountKey $storageAccountKey.Primary -StorageAccountName $storageAccountKey.StorageAccountName
$result = New-AzureStorageContainer -Name $storageContainerName -Permission Off -Context $storageContext
# 4th: New-AzureVM needs the CurrentStorageAccountName to be set.
Set-AzureSubscription -SubscriptionName $subscriptionName -CurrentStorageAccountName $storageAccountName
# 5th: create new VM configuration.
$vmConfig = New-AzureVMConfig -ImageName $imageNameWS2012R2 -InstanceSize Small -Name $vmName `
-MediaLocation "https://$storageAccountName.blob.core.windows.net/$storageContainerName/$vmName.vhd"
# 6th: add provisioning data to VM configuration.
Add-AzureProvisioningConfig -Windows -AdminUsername $adminUsername -Password $adminPassword -VM $vmConfig
# 7th: create new VM and let it start.
New-AzureVM -ServiceName $serviceName -Location $location -VMs $vmConfig
@pkirch

This comment has been minimized.

Copy link
Owner Author

commented Jan 28, 2015

This sample script is used in the Microsoft Virtual Academy Course "PowerShell: Azure-Automatisierung für Einsteiger" at http://www.microsoftvirtualacademy.com/training-courses/powershell-azure-automatisierung-f-r-einsteiger-.

@pkirch

This comment has been minimized.

Copy link
Owner Author

commented Feb 2, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.