Last active
August 29, 2015 14:13
-
-
Save pkirch/553defb9c3b71018aeca to your computer and use it in GitHub Desktop.
This sample creates a new cloud service, storage account and VM.
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
# 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 |
This code sample is used in my blog post at http://blogs.msdn.com/b/pkirchner/archive/2015/02/02/grundlagen-azure-amp-powershell-vms-erstellen.aspx.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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-.