Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
In diesem Beitrag unserer Azure PowerShell Serie erstellen wir per PowerShell eine Virtuelle Maschine auf Windows Azure. Konkreter: wir erstellen eine Windows Server 2012 R2 Datacenter VM.
Im Windows Azure Management Portal sieht das folgendermaßen aus:
Hierbei wird zuerst eine Affinitätsgruppe und ein Speicherkonto erstellt, mit dem die Virtuelle Maschine assoziiert ist. Die Namen muss man selber in Abschnitt 1 einstellen. Der interessante Teil ist dann Abschnitt 3, wo das Image für die VM spezifiziert wird; in diesem Fall: Windows Server 2012 R2. In der Grafik oben sehen wir aber noch eine weit größere Auswahl an Images, die man hernehmen kann.
001002003004005006007008009010011012013014015016017018019020021022023024025026027028029030031032033034035036037038039040041042043044045046047048049050051052053054055056057058059060061062063064065066067068069070071072073074075076077078079080081082083084085086087088089090091092093094095 | #################################################### Create virtual machine# ISE is just awesomeise#################################################### 0. Azure Account DetailsAdd-AzureAccount$subName = "<AzureSbscriptionName>"Select-AzureSubscription $subName# Azure account details automatically set$subID = Get-AzureSubscription -Current | %{ $_.SubscriptionId } #################################################### 1. Input information# variables to storage accounts$___location = "<DatacenterLocation>" #e.g. North Europe, West Europe, etc.$storageAccount = "<StorageAccountName>"$defaultContainer = "<StorageContainerName>"$affinityGrp = "<AffinityGroup>"$instanceSize = "Large" #Small, Large, etc.# variables to VM$vmName = "<vmName>"$adminLogin = "<vmLogin>"$adminPasswd = "<vmPasswd>"#################################################### 2. Provision storage# a. Create affinity groupNew-AzureAffinityGroup -Name $affinityGrp -Location $___location# b. Provision storage account#New-AzureStorageAccount -StorageAccountName $storageAccount -AffinityGroup $affinityGrpNew-AzureStorageAccount -StorageAccountName $storageAccount -Location $locationSet-AzureStorageAccount -StorageAccountName $storageAccount -GeoReplicationEnabled $false# c. Set storage account as default one, otherwise you will not be able to build your VMSet-AzureSubscription -SubscriptionName $subName -CurrentStorageAccount $storageAccount# d. Check if the storage account is set as the default oneGet-AzureSubscription -Current#################################################### 3. Build VM# a. Pick VM image$vmImage = Get-AzureVMImage ` | Where-Object -Property ImageFamily -ilike "Windows Server 2012 R2*" ` | Sort-Object -Descending -Property PublishedDate ` | Select-Object -First(1)# automatically set for you: credentials to VM$vmCreds = New-Object System.Management.Automation.PSCredential($adminLogin,($adminPasswd ` | ConvertTo-SecureString -AsPlainText -Force))# b. Build VM#New-AzureQuickVM -ImageName $VMImage.ImageName -Windows -Name $VMName -ServiceName $VMName `# -AdminUsername $adminLogin -Password $adminPasswd -AffinityGroup $affinityGrpNew-AzureQuickVM -ImageName $vmImage.ImageName -Windows -Name $vmName -ServiceName $vmName ` -AdminUsername $adminLogin -Password $adminPasswd -Location $___location -InstanceSize $instanceSize############################################### # 4. Get status, properties, etc. # a. Check statusGet-AzureVM -Name $vmName -ServiceName $vmName# b. Stop, start or restart the VMStop-AzureVM -Name $vmName -ServiceName $vmNameStart-AzureVM -Name $vmName -ServiceName $vmNameRestart-AzureVM -Name $vmName -ServiceName $vmName# c. Clean upRemove-AzureVM -ServiceName $vmName -Name $vmName -DeleteVHD############################################### # 5. clean up # a. Remove VM & cloud serviceRemove-AzureVM -Name $vmName -ServiceName $vmNameRemove-AzureVM -ServiceName $vmName# b. Remove storage accountRemove-AzureStorageAccount -StorageAccountName $storageAccount |
Comments
- Anonymous
January 01, 2003
:) My thinking exactly! - Anonymous
March 24, 2014
In dieser Serie werde ich meine Lieblings-PowerShell-Skripte veröffentlichen, die mir das Leben um einige - Anonymous
April 13, 2014
who says we need to know different languages to understand code! - Anonymous
May 08, 2014
Thanks...excellent starting point for me :)