0% found this document useful (0 votes)
19 views

Lab CLIPw SH Cloud Shell

Uploaded by

amina.arbah
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views

Lab CLIPw SH Cloud Shell

Uploaded by

amina.arbah
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 10

Scenario

In this lab you will use the Azure CLI and Azure PowerShell commandlets to manage
Azure resources. You will run the commands from the Azure Cloud Shell, which you
will open from the Azure Portal. You will list resources and create a resource using both
the CLI and PowerShell.

Note: You do not need experience scripting nor do you even need experience using the
command line to complete this lab. All of the commands that you need are in the
solution section. If you are new to scripting, read through the tasks and go directly to
the solution and follow the steps there.

Note: The commands in this lab to create environment variables using the CLI and
PowerShell are more advanced. They use techniques in bash shell and PowerShell that
are beyond this course. These commands are given to you and you do not need to spend
time trying to figure them out.

Lab Objectives

In this lab, you will do the following:

1. Open a Cloud Shell session


2. Retrieve resource information by using the Azure CLI
3. Use the Azure CLI to provision a storage account
4. Use the Azure PowerShell commandlets to retrieve resource information
5. Use the Azure PowerShell commandlets to provision a storage account

Tasks

Tasks

Task 0. Start the lab

Log into the Azure portal using the provided lab credentials.

Task 1. Open a Cloud Shell session

Open Cloud Shell from the Azure Portal. Use the bash shell and create a new storage
account in your resource group for the Cloud Shell storage.
Task 2. Retrieve resource information by using the Azure CLI

For this task, you will use the Azure CLI to retrieve information on services and
resources in Azure. You will start by listing the command groups available in the CLI,
then use the CLI to return information on subscriptions that you have access to. You
will then use the CLI to list resource groups that you have access to. Finally, you will
display information about a virtual machine. To complete this task:

 Execute the following command to discover the top level groups of commands for the
Azure CLI:

az help

 List the commands in the az account group.


 Execute a CLI command to list the Azure subscriptions in tabular format.
 Execute a CLI command to list the resource groups that you have access to in tabular
format.
 Execute the following command to create an environment variable named rg with the
name of your resource group:

rg=$(sed -e 's/^"//' -e 's/"$//' <<<$(az group list --query


"[].name| [0]"))

 Execute the following command to view the details of a virtual machine named lab-vm
in the resource group identified by the $rg environment variable.

Task 3. Use the Azure CLI to provision a storage account

For this task you will use the Azure CLI to create a Storage Account in your resource
group and region. To complete this task:

 Execute the following command to store the region of your resource group in an
environment variable named location:

location=$(sed -e 's/^"//' -e 's/"$//' <<<$(az group list --query


"[].location|[0]"))

 List the Azure CLI commands for Storage Accounts.


 Use the Azure CLI to create a storage account with the following properties:

Setting Value

Resource
$rg
group
Setting Value

Name <a unique name>

Location $location

Note: The name must be a globally unique combination of lower case letters and
numbers.

 Use the Azure CLI to verify that the Storage Account was created.

Task 4. Use the Azure PowerShell commandlets to retrieve resource


information

For this task, you will load PowerShell in Cloud Shell and retrieve information on
services and resources in Azure. You will start by using an Azure PowerShell
commandlet to return information on subscriptions that you have access to. You will
then use a commandlet to list resource groups that you have access to. Finally, you will
display information about a virtual machine. To complete this task:

 Execute the following command to start Powershell in your Cloud Shell session:

pwsh

 Execute the following commandlet to list the commandlets for Azure subscriptions:

Get-Command -noun AzSubscription*

 Use the Get-Help commandlet to display information on the commandlet used to


retrieve subscription information.
 Run the following command to get help on displaying output in tabular format:

Get-Help Format-Table -Detailed

 Use the Azure PowerShell commandlet to list the Azure subscriptions in tabular format.
 List the resource groups that you have access to in tabular format.
 Execute the following to create an environment variable with the name of your resource
group:

$rg=(Get-AzResourceGroup)[0].ResourceGroupName

 Execute the following to create an object that represents your virtual machine:

$vm = Get-AzVm -Name lab-vm -ResourceGroup $rg


 Execute the following to display general information for your virtual machine:

$vm

 Execute the following to display OS (operating system) information for your virtual
machine:

$vm.OSProfile

Task 5. Use the Azure PowerShell commandlets to provision a storage


account

For this task you will use the Azure PowerShell commandlets to create a Storage
Account in your resource group and region. To complete this task:

 Execute the following to store the region of your resource group in an environment
variable named location:

$location=(Get-AzResourceGroup)[0].Location

 List the commandlets for Storage Accounts (-Noun AzStorageAccount*).


 Use the Get-Help commandlet to learn how to create a storage account.
 Create a storage account with the following properties:

Setting Value

Resource
$rg
group

Name <a unique name>

Location $location

 Verify that your storage account was created.

Solutions

Task 0 Solution: Log in to the Azure portal with your lab credentials
 Select a region to run your lab in.
 Choose the Start lab button and then choose Open lab. On the next page, agree to the
terms and conditions and then choose Continue.

 You will be presented with access credentials as shown in the following example. Open
the Azure Portal Login link in a new private window.
 The URL will take you to the Microsoft Azure sign-in page. Sign in using the
Username you were provided with and choose Next.
 Enter the password you were provided with and choose Sign in. If you're prompted to
save the password, choose Not Now.
 You will be redirected to your resource group in the Azure portal.

Task 1 Solution: Open a Cloud Shell session


 Select the Cloud Shell icon to the right of the search box at the top of the Azure

portal.
 Select Bash on the Welcome to Azure Cloud Shell prompt.

 Select the Show advanced settings link.


 Accept the defaults for Subscription and Cloud Shell region.
 Verify that the resource group matches the resource group on the lab credentials page.
 Create a new storage account with a unique name. You should be able to use <your
initials>ine<yyyymmdd>, where <your initials> is your initials and <yyyymmdd> is the
date in integer format. The account name must be all lower case letters and numbers.
 Create a new File share named cloudshell.
 Select the Create storage button.
 Once the Cloud Shell loads, run the following command to verify that you are
properly connected:

az group list -o table

For a demonstration of this task, watch the corresponding course video .

Task 2 Solution: Retrieve resource information by using the Azure


CLI

Next you will use the intrinsic help capabilities of the Azure CLI to find commands to
list subscriptions, resource groups, and virtual machines. To complete this task:

 Execute the following command to discover the top level groups of commands for the
Azure CLI:

az help

 Execute the following command to list the commands in the account group:

az account --help

 Execute the following command to find out how to list Azure subscriptions:

az account list --help

 Execute the following command to list the Azure subscriptions in tabular format:

az account list -o table

 Execute the following command to learn how to list the resource groups that you have
access to:

az group list --help


 List the resource groups that you have access to in tabular format:

az group list -o table

 Execute the following command to create an environment variable with the name of
your resource group:

rg=$(sed -e 's/^"//' -e 's/"$//' <<<$(az group list --query


"[].name| [0]"))

 Execute the following command to learn how to show the details of a virtual machine:

az vm show --help

 Execute the following command to view the details of your virtual machine:

az vm show -n lab-vm -g $rg

For a demonstration of this task, watch the corresponding course video .

Task 3 Solution: Use the Azure CLI to provision a storage account


 Execute the following command to store the region of your resource group in an
environment variable named location:

location=$(sed -e 's/^"//' -e 's/"$//' <<<$(az group list --query


"[].location|[0]"))

 Execute the following command to list the commands for Storage Accounts:

az storage account --help

 Execute the following command to learn how to create a storage account:

az storage account create --help

 Execute the following command to create a storage account. Replace <unique name>
with a unique name consisting of lower case letters and numbers:

az storage account create -g $rg -l $location --kind StorageV2 --


sku Standard_LRS -n <unique name>

 Execute the following command to verify that your storage account was created:

az storage account list -o table

For a demonstration of this task, watch the corresponding course video .

Task 4 Solution: Use the Azure PowerShell commandlets to retrieve


resource information
 Execute the following command to start Powershell in your Cloud Shell session:

pwsh

 Execute the following commandlet to list the commandlets for Azure subscriptions:

Get-Command -noun AzSubscription*

- Execute the following to find out how to list Azure subscriptions:

Get-Help Get-AzSubscription -Detailed

 Execute the following to list the Azure subscriptions in tabular format:

Get-AzSubscription | Format-Table

 Execute the following to learn how to list the resource groups that you have access to:

Get-Help Get-AzResourceGroup -Detailed

 List the resource groups that you have access to in tabular format

Get-AzResourceGroup | Format-Table

 Execute the following to create an environment variable with the name of your resource
group:

$rg=(Get-AzResourceGroup)[0].ResourceGroupName

 Execute the following to learn how to show the details of a virtual machine:

Get-Help Get-AzVm -Detailed

 Execute the following to create an object that represents your virtual machine:

$vm = Get-AzVm -Name lab-vm -ResourceGroup $rg

 Execute the following to display general information for your virtual machine:

$vm

 Execute the following to display OS (operating system) information for your virtual
machine:

$vm.OSProfile

For a demonstration of this task, watch the corresponding course video .

Task 5 Solution: Use the Azure PowerShell commandlets to provision a


storage account
 Execute the following to store the region of your resource group in an environment
variable named location:

$location=(Get-AzResourceGroup)[0].Location

 Execute the following command to list the commandlets for Storage Accounts:

Get-Command -Noun AzStorageAccount*

 Execute the following command to learn how to create a storage account:

Get-Help New-AzStorageAccount -Detailed

 Execute the following commandlet to create a storage account. Replace <unique name>
with a unique name consisting of lower case letters and numbers:

New-AzStorageAccount -ResourceGroup $rg -Location $location -Kind


StorageV2 -Sku Standard_LRS -n <unique name>

 Execute the following to verify that your storage account was created:

Get-AzStorageAccount | Format-Table

For a demonstration of this task, watch the corresponding course video .

You might also like