In this demonstration, you will see how to:
Create virtual machines and cloud services using the Microsoft Azure PowerShell.
Delete virtual machines and cloud services using the Microsoft Azure PowerShell.
Demonstration Steps
Create a virtual machine using Microsoft Azure PowerShell
1. On the taskbar, right-click Microsoft Azure PowerShell and click Run ISE as Administrator. Click Yes when prompted.
2. In the PowerShell ISE, in the command prompt pane, enter the following command to add an Azure account to the local PowerShell environment:
Add-AzureAccount
3. When prompted, sign in using the Microsoft account associated with your Azure subscription.
4. In the PowerShell ISE, in the command prompt pane, enter the following command and press Enter:
Get-AzureSubscription
5. In the PowerShell ISE, click File and then click Open.
6. In the Open dialog, browse to D:\Demofiles\Mod03\.
7. Click ExampleCommands.ps1 and then click Open.
8. If the Script pane is not visible, on the View menu, click Show Script Pane.
9. In the PowerShell ISE, in the command prompt pane, select the subscription name, then right-click, and click Copy.
10. In the PowerShell ISE, in the Script pane, paste the subscription name.
11. In the PowerShell ISE, in the command prompt pane, enter the following command and press Enter:
Get-AzureStorageAccount
12. In the PowerShell ISE, in the command prompt pane, select the storage account name, then right-click, and click Copy.
13. In the PowerShell ISE, in the Script pane, paste the storage account name.
14. In the PowerShell ISE, in the Script pane, locate the following code:
Set-AzureSubscription -CurrentStorageAccountName <#Copy your storage account name here#> -SubscriptionName <#Copy your subscription name here in quote marks#>
15. Replace <#Copy your storage account name here#> with your storage account name.
16. Replace <#Copy your subscription name here in quote marks#> with your subscription name; ensure that you use single quote marks around the name.
MCT USE ONL Y. STUDENT USE PROHIBITED
3-22 Implementing Virtual Machines
17. In the PowerShell ISE, in the Script pane, select the code you have just edited.
18. On the toolbar, click the Run Selection button and wait for the script to complete.
19. In the PowerShell ISE, in the Script pane, select the following code:
$svcName = "20533lab03cloudsvc" + (Get-AzureStorageAccount).Label.Substring(15,6)
20. On the toolbar, click the Run Selection button and wait for the script to complete.
21. In the PowerShell ISE, in the command prompt pane, type the following and press Enter:
$svcName
22. This variable should now contain a unique cloud service name, using the same unique number used to create the storage account during lab preparation.
23. In the PowerShell ISE, in the Script pane, select the following code:
$location = (Get-AzureStorageAccount).Location
24. On the toolbar, click the Run Selection button and wait for the script to complete.
25. In the PowerShell ISE, in the command prompt pane, type the following and press Enter:
$location
26. This variable should now contain the Azure region used during lab preparation.
27. In the PowerShell ISE, in the Script pane, select the following code:
$osimage = (Get-AzureVMImage | where {$_.ImageFamily -like "Windows Server 2012 R2 Datacenter*"} | sort PublishedDate -Descending)[0].ImageName
28. On the toolbar, click the Run Selection button and wait for the script to complete.
29. In the PowerShell ISE, in the Script pane, select the following code:
New-AzureQuickVM -Windows -ImageName $osimage -Location $location -Name “DemoVM1” – ServiceName $svcName -InstanceSize Small -AdminUserName Student –Password
'Pa$$w0rd123'
30. On the toolbar, click the Run Selection button and wait for the script to complete.
31. In the PowerShell ISE, in the Script pane, select the following code:
NewAzureQuickVM Windows ImageName $osimage Name “DemoVM2” –ServiceName $svcName -InstanceSize Small -AdminUserName Student –Password 'Pa$$w0rd123'
32. On the toolbar, click the Run Selection button and wait for the script to complete.
33. In the Microsoft Azure Preview Portal, click BROWSE, then click Virtual machines.
34. On the Virtual machines blade, note the two new virtual machines listed, called DemoVM1 and DemoVM2.
MCT USE ONL Y. STUDENT USE PROHIBITED
Microsoft Azure for IT Professionals 3-23
Delete virtual machines and a cloud service using Microsoft Azure PowerShell
1. In the PowerShell ISE, in the command prompt pane, enter each of the following commands and press Enter after each one:
Remove-AzureVM –ServiceName $svcName –Name DemoVM1 Remove-AzureVM –ServiceName $svcName –Name DemoVM2 Remove-AzureService -ServiceName $svcName
2. In the Confirm dialog box, click Yes.
3. In the Microsoft Azure Preview Portal, click BROWSE, then click Virtual machines.
4. On the Virtual machines blade, note the two virtual machines called, DemoVM1 and DemoVM2, are no longer listed.
5. Close the Virtual machines blade.
6. On the Microsoft Azure Preview Portal home screen, click the AZURE PORTAL tile to open the full management portal.
7. In the Microsoft Azure Management Portal, click CLOUD SERVICES.
Verify that the cloud service is not listed.
Reset the Environment
1. Close all open applications without saving any files.
2. On the taskbar, right-click Microsoft Azure PowerShell, and then click Run as administrator. In the User Account Control dialog, click Yes.
3. Type the following command, and then press Enter:
Reset-Azure
4. When prompted, sign in using the Microsoft account associated with your Azure subscription.
Note: This script may remove Azure services in your subscription. It is therefore recommended that you use an Azure trial pass that was provisioned specifically for this course, and not your own Azure account.
The script will take 5-10 minutes to reset your Microsoft Azure environment, ready for the next lab.
The script removes all storage, VMs, virtual networks, cloud services, and resource groups. The script does not remove the Automation account (or the organizational account); this can either be manually deleted or you can leave it in place, as it does not affect subsequent labs.
Important: The script may not be able to get exclusive access to a storage account to delete it (if this occurs, you will see an error). If you find objects remaining after the reset script is complete, you can re-run Reset-Azure script, or use the full Azure Management Portal to manually delete all the objects in your Azure subscription, with the exception of the default directory.
MCT USE ONL Y. STUDENT USE PROHIBITED
3-24 Implementing Virtual Machines