• No results found

Demonstration: Using Azure PowerShell

In document 20533B-ENU-TrainerHandbook (Page 42-45)

In this demonstration, you will see how to:

 Use certificate-based authentication.

 Use Azure AD-based authentication.

 Use Azure PowerShell Cmdlets.

Demonstration Steps

Use Certificate-Based Authentication

1. Ensure that you have completed the previous demonstration in this module, and are logged on to the 20533B-MIA-CL1 virtual machine as Student with the password Pa$$w0rd.

2. On the taskbar, right-click Microsoft Azure PowerShell and click Run ISE as Administrator. Click Yes when prompted.

3. In the Windows PowerShell interactive scripting environment, in the command prompt pane, enter the following command to generate and download a management certificate:

Get-AzurePublishSettingsFile

4. When Internet Explorer opens, sign in using the Microsoft account associated with your Azure subscription. Then when prompted to open or save the certificate file, in the Save drop-down list, click Save as, and save the file as azure-credentials.publishsettings in the D:\Demofiles\Mod01 folder (overwriting any existing file of this name).

5. When the download has completed, close Internet Explorer.

6. In the PowerShell ISE, in the command prompt pane, enter the following command to import the certificate:

Import-AzurePublishSettingsFile D:\Demofiles\Mod01\azure-credentials.publishsettings

MCT USE ONL Y. STUDENT USE PROHIBITED

Implementing Microsoft Azure Infrastructure Solutions 1-23

7. In the PowerShell ISE, in the command prompt pane, enter the following command to view the subscriptions that are connected to the local PowerShell session:

Get-AzureSubscription

8. Verify that your subscription is listed.

9. Start Internet Explorer, browse to http://azure.microsoft.com, click Portal, and sign in using the Microsoft account that is associated with your Azure subscription.

10. On the SETTINGS page, on the MANAGEMENT CERTIFICATES tab, find the most recently created certificate and note its expiry date. Then, at the bottom of the page, note the option to upload your own certificate, and close Internet Explorer.

11. In the Windows PowerShell ISE, in the output from the previously executed Get-AzureSubscription statement, note the name of your subscription. Then enter the following command to delete it from the local PowerShell environment:

Remove-AzureSubscription -SubscriptionName "<your_subscription_name>" -Force

12. Note the warnings that are displayed, and then re-execute the following command to verify that the subscription has been deleted (if there are no subscriptions, the command returns an empty line):

Get-AzureSubscription

Use Azure AD Authentication

1. 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

2. When prompted, sign in using the Microsoft account associated with your Azure subscription.

3. In the PowerShell ISE, in the command prompt pane, enter the following command to view the Azure accounts in your local PowerShell environment, and verify that your account is listed:

Get-AzureAccount

4. Enter the following command to view the subscriptions that are connected to the local PowerShell session, and verify that your subscription is listed again:

Get-AzureSubscription

Use Azure PowerShell Cmdlets

1. In the PowerShell ISE, in the command prompt pane, enter the following command to view the cmdlets in the Azure module. If you are prompted to run Update-Help, click No:

Get-Command -Module Azure | Get-Help | Format-Table Name, Synopsis

2. Review the output, and note the large number of cmdlets available.

3. Enter the following command to view the syntax for the Get-AzureWebsite cmdlet:

Get-Help Get-AzureWebsite

MCT USE ONL Y. STUDENT USE PROHIBITED

1-24 Introduction to Microsoft Azure

4. Review the output. Then enter the following command to clear the screen:

cls

5. In the PowerShell ISE, click File and then click Open.

6. In the Open dialog, browse to D:\Demofiles\Mod01\.

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 Script pane, highlight the following code:

foreach ($store in Get-AzureStorageAccount)

{ Write-Host $store.StorageAccountName : $store.StatusOfPrimary }

10. On the toolbar, click Run Selection and wait for the script and its results to be displayed in the command prompt pane. The results should list the name and status of the storage account you created in the previous demonstration.

11. In the Console pane, type the following command, and then press Enter:

Switch-AzureMode -Name AzureResourceManager

12. In the Script pane, highlight the following code:

foreach ($rg in Get-AzureResourceGroup) { Write-Host " "

Write-Host $rg.ResourceGroupName Write-Host $rg.ResourcesTable Write-Host " "

}

13. On the toolbar, click Run Selection and wait for the script and its results to be displayed in the command prompt pane. The results should list each resource group in your subscription, and a table of the resources in each resource group.

14. Close the Windows PowerShell ISE without saving any script files.

Reset the Environment

1. On the taskbar, right-click Microsoft Azure PowerShell, and then click Run as administrator. In the User Account Control dialog, click Yes.

2. Type the following command, and then press Enter:

Reset-Azure

3. 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.

MCT USE ONL Y. STUDENT USE PROHIBITED

Implementing Microsoft Azure Infrastructure Solutions 1-25

In document 20533B-ENU-TrainerHandbook (Page 42-45)