Skip to content

Instantly share code, notes, and snippets.

@pkirch
Last active August 29, 2015 14:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save pkirch/553defb9c3b71018aeca to your computer and use it in GitHub Desktop.
Save pkirch/553defb9c3b71018aeca to your computer and use it in GitHub Desktop.
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
Copy link
Author

pkirch 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
Copy link
Author

pkirch commented Feb 2, 2015

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