Beruflich Dokumente
Kultur Dokumente
1. Login to Azure
For this challenge, you have either elected to use your own subscription or have created a new Azure
subscription using the provided Azure Pass (or Free Trial). If you want to switch to use the provided Azure
Pass the promotion code is displayed on the My Account page on the http://challenge.azurecon.com web
site. If there is no promo code displayed, you will need to use the free trial http://azure.microsoft.com/pricing/free-trial.
Azure has TWO management portals - the classic portal (http://manage.windowsazure.com) and a new
portal that is in Preview at http://portal.azure.com. You will use the Preview portal in this challenge.
1.
2.
Enter your Microsoft Account email address and password for the Microsoft Account you
associated with your Azure Pass or your own subscription.
3.
You will now be in your Azure subscription (see opposite) and from here you can create and
manage Azure services.
2.
Click the Windows Standalone link (for the latest release which might not be
0.9.8 as shown) and then follow the instructions to RUN the .msi file and complete
the installation.
On your machine, click the WINDOW button and type PowerShell ISE.
2.
Select the PowerShell ISE application in the list and PowerShell ISE will launch.
3.
First click the View menu and choose Show Script Pane.
4.
Page | 1
If you get any errors here, you might need to restart your machine so that PowerShell ISE can pick-up the powershell modules.
A login dialog will fire up, when it does, enter the same Microsoft Account credentials when you logged into your Azure subscription. You will
then see in the command prompt window, some identity details for your subscription.
5.
In the command window, cut/paste these two commands press Enter after each one.
import-module "C:\Program Files (x86)\Microsoft SDKs\Azure\PowerShell\ServiceManagement\Azure\azure.psd1"
import-module "C:\Program Files (x86)\Microsoft SDKs\Azure\PowerShell\ResourceManager\AzureResourceManager\AzureResourceManager.psd1"
6.
Type:
Get-AzureSubscription
This will list all the subscriptions that your login has access to likely it will
be only one. If you have multiple subscriptions, you need to pick a
particular subscription that you are going to use for this challenge.
7.
Type:
Select-AzureSubscription SubscriptionName
<insert the name of the subscription you want to
use> e.g. Azure Pass
Now, operations you perform will be done against the selected
subscription, you dont have to supply that value.
You need to create a storage account for your virtual disks and a storage account
needs to be put in an Azure region but how do you know which region you can put your storage account in? Your subscription might not have access to
all the regions.
8.
Type:
AzureResourceManager\Get-AzureLocation
9.
Wow, thats a list of all types of resources in Azure and for each one what the possible locations available are for your subscription. Lets narrow
this down to just the locations for storage accounts:
10.
Thats better. Now you are going to start writing a script in the script window in
ISE not issuing the commands one at a time. You are becoming a
programmer..! In the Script window, paste in the same command from
above. Press the RUN button on the tool bar (or Debug ->Run/Continue).
Same result? Yes.
12.
Just before the Get-AzureLocation command on the same line (still in the
script window). Type $storagelocations =
13.
Press RUN again this time no output. Thats because you just caused the
output of the Get-AzureLocations command to be assigned to the $storagelocations variable. This now holds some data about your storage
locations.
14.
You can get this data by referencing the variable $storagelocations and its properties such as Name and Locations.
15.
$storagelocations.Name
$justlocations = $storagelocations.Locations
"Random Region=" + (Get-Random -input $justlocations)
16.
Press Run several times. You will see that each time a new region is selected.
You can also see how to output text. Pretty useful.
17.
Select by clicking the line number 4 (see A) just the Random Region line. In
the toolbar indicated by (B) this is the Run Selection button it will only
execute whatever is highlighted NOT the whole script. Very useful for
debugging.
18.
Press Run Selection button a few times only this command is executed.
Page | 2
19. So your little program is working. Change the last line to the following so that the region itself is stored in a variable.
$region = (Get-Random -input $justlocations)
You can write commands to create all the resources you need for the VM as you have been doing in PowerShell already.
b.
You can create a definition of the resources (called a template) and then just use PowerShell and a simple script to hand that
template off to Azure.
You will be doing (a). There is a separate challenge on Azure Resource Manager Templates that covers (b).
Ok, you can now start writing the code/script to create your Virtual Machine. However, a Virtual Machine is dependent on a number of other services to be
created. For example, a VM must be attached to a resource group (which you have to create first). A VM needs virtual disks and these have to be stored in a
storage account which YES you have to create first So BEFORE you can create your VM, you have to create all the dependent resources.
1.
After your last line of code ($region = (Get-Random input ) copy/paste these lines.
$rgname = "VMinCode"
$storagename = "<alias>vmdiskstore"
New-AzureResourceGroup -Name $rgname -location $region
AzureResourceManager\New-AzureStorageAccount StorageAccountName $storagename Location
$region -ResourceGroupName $rgname -Type Standard_LRS
2.
Replace <alias> on the second line above - including the angle brackets with your
alias. This will be the name of your storage account it CANNOT have any symbols
in its name (e.g. bsmithvmstore).
3.
Press RUN. After a few seconds you will see in the command window that your
storage account creation and resource group was successful.
4.
Switch back to the Azure Portal and click on Resource Groups. Click the
VMinCode group and you will see it contains a single resource your storage
account.
5.
Your VM needs a few other things as well it needs a network (which needs a
subnet) and it needs a Virtual Network Interface Card (a Nic) and it needs a public IP
address. So lets create all these. Copy/Paste the script below at the end of your
current script but DO NOT press run.
$vmDNSname = "<alias>-vmincode"
$subnetName = "Subnet-1"
$subnet = New-AzureVirtualNetworkSubnetConfig -Name $subnetName -AddressPrefix "10.0.64.0/24"
$vnet = New-AzureVirtualNetwork -Name "VNET" -ResourceGroupName $rgname -Location $region -AddressPrefix
"10.0.0.0/16" -Subnet $subnet
$subnet = Get-AzureVirtualNetworkSubnetConfig -Name $subnetName -VirtualNetwork $vnet
$pip = New-AzurePublicIpAddress -ResourceGroupName $rgname -Name "vip1" -Location $region AllocationMethod Dynamic -DomainNameLabel $vmDNSname
$nic = New-AzureNetworkInterface -ResourceGroupName $rgname -Name "nic1" -Subnet $subnet -Location
$region -PublicIpAddress $pip -PrivateIpAddress "10.0.64.4"
6.
7.
Now you dont want to run the entire script, just the last section you pasted in.
Highlight that section (a) and press the RUN SELECTION button (b)
8.
Switch back to the portal and you should see all the resources you have created so far.
Page | 3
5. Creating Your VM
Now its time to create your VM. The basic approach is to use a variable to hold all the information needed for the VM creation and then pass that variable
to the VM creation command. This special variable is called a VMConfig object. For our VM we need to define things like the credentials to use for the
admin login, the size of the VM, what OS will be installed in the VM, the name of the operating system disk and so on.
1.
Copy/paste in these 5 lines of code. SELECT the 5 lines and press the RUN SELECTION button.
$publisher = "MicrosoftWindowsServer"
$offer = "WindowsServer"
$sku = "2012-R2-Datacenter"
$version = "latest"
$cred = Get-Credential
2.
You will get a dialog asking you for a username/password and whatever you enter gets securely passed into the $cred variable. This will be the
username/password for the virtual machine you are creating. Suggest you use <alias>admin e.g. bsmithadmin as the username and a password
you can remember write it down..!
3.
In the command window (at the bottom left), type $cred. This will display the value of the username but not the password.
4.
Back in your script window at the top, copy/paste these 6 lines of script:
$vmConfig = AzureResourceManager\New-AzureVMConfig -VMName $vmDNSname -VMSize "Standard_A1"
AzureResourceManager\Set-AzureVMOperatingSystem -VM $vmconfig -Windows -ComputerName "contoso-w1" Credential $cred -ProvisionVMAgent -EnableAutoUpdate
$vmConfig | AzureResourceManager\Set-AzureVMSourceImage -PublisherName $publisher -Offer $offer -Skus
$sku -Version $version
$vmConfig | AzureResourceManager\Set-AzureVMOSDisk -Name "$vmDNSname-w1" -VhdUri
"https://$storagename.blob.core.windows.net/vhds/$vmDNSname-w1-os.vhd" -Caching ReadWrite -CreateOption
fromImage
$vmConfig | AzureResourceManager\Add-AzureVMNetworkInterface -Id $nic.Id
AzureResourceManager\New-AzureVM -ResourceGroupName $rgname -Location $region -VM $vmConfig
9.
Highlight the 6 lines and press RUN SELECTION this will create your Virtual Machine.
10.
11.
12.
13.
14.
--- END OF LAB --Go back to the AzureCon Challenge web site (http://challenge.azurecon.com) and complete the challenge question to get your points.
REMEMBER: You only have one chance at the question, make sure you really know the answer!
Page | 4