Azure CLI and Powershell Cmds Flashcards

1
Q

What is the first CLI command you’ll most likely have to do?

A

Create a resource group

az group create –name {name} –location eastus

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How do you create a virtual machine in Azure CLI?

A

az vm create –resource-group

  • -name
  • -image
  • -generate-ssh-keys
  • -output json
  • -verbose
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How do you show information about a resource?

A

az {resourceQuery (such as vm)} show –name

–query

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How would you create a VM in powershell?

A
New-AzResourceGroup -Name 'name' -Location 'westus2'
New-AzVm
 - ResourceGroupName
 -Name
 -Location
 -VirtualNetworkName
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What fields do you need for an ARM template deploying a vm resource?

A
adminUsername
adminPassword
dnsLabelPrefix
publicIpName
publicIpSku
OSVersion
vmSize
Location
vmName
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How would you create an azure container instance?

A

In CLI
az container create –resource-group myResourceGroup –name mycontainer –image mcr.microsoft.com/azuredocs/aci-helloworld –dns-name-label aci-demo –ports 80

In PowerShell
New-AzContainerGroup -ResourceGroupName myResourceGroup -Name mycontainer -Image mcr.microsoft.com/windows/servercore/iis:nanoserver -OsType Windows -DnsNameLabel aci-demo-win

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How would you create an azure container registry?

How about logging in?

A

CLI
az acr create –resource-group myResourceGroup \
–name myContainerRegistry007 –sku Basic

PowerShell
$registry = New-AzContainerRegistry -ResourceGroupName “myResourceGroup” -Name “myContainerRegistry007” -EnableAdminUser -Sku Basic

Connect-AzContainerRegistry -Name $registry.Name

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What are the steps to create and deploy a web app using web app services?

A

az group create –name $resourceGroup –location “$location” –tag $tag

az appservice plan create –name $appServicePlan –resource-group $resourceGroup –sku FREE

az webapp create –name $webapp –resource-group $resourceGroup –plan $appServicePlan

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

How do you deploy code to a webapp using CLI?

A

With FTP
creds=($(az webapp deployment list-publishing-profiles –name $webapp –resource-group $resourceGroup \
–query “[?contains(publishMethod, ‘FTP’)].[publishUrl,userName,userPWD]” –output tsv))

# Use cURL to perform FTP upload. You can use any FTP tool to do this instead. 
curl -T index.html -u ${creds[1]}:${creds[2]} ${creds[0]}/

With GitHub
az webapp deployment source config –name $webapp –resource-group $resourceGroup \
–repo-url $gitrepo –branch master –manual-integration

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How would you deploy deployment slots with azure cli?

A
# Create a deployment slot with the name "staging".
az webapp deployment slot create --name $webapp --resource-group $resourceGroup --slot staging
# Deploy sample code to "staging" slot from GitHub.
az webapp deployment source config --name $webapp --resource-group $resourceGroup --slot staging --repo-url $gitrepo --branch master --manual-integration

Copy the result of the following command into a browser to see the staging slot.
site=”http://$webapp-staging.azurewebsites.net”
echo $site
curl “$site”

Swap the verified/warmed up staging slot into production.
az webapp deployment slot swap –name $webapp –resource-group $resourceGroup \
–slot staging

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

How would you deploy a function app?

A

az functionapp create –name –resource-group –storage-account

func azure functionapp publish

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

How would you create a Cosmos DB With Azure CLI?

A
# Create a Cosmos account for SQL API
echo "Creating $account"
az cosmosdb create --name $account --resource-group $resourceGroup --default-consistency-level Eventual --locations regionName="$location" failoverPriority=0 isZoneRedundant=False --locations regionName="$failoverLocation" failoverPriority=1 isZoneRedundant=False

Create a SQL API database
echo “Creating $database”
az cosmosdb sql database create –account-name $account –resource-group $resourceGroup –name $database

az cosmosdb sql container create with –max-throughput 1000 creates an Azure Cosmos SQL (Core) container with autoscale capability.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

How would you create a Cosmos DB with Powershell?

A

$account = New-AzCosmosDBAccount -ResourceGroupName $resourceGroupName `

- LocationObject $locations -Name $accountName -ApiKind $apiKind -Tag $tags `
- DefaultConsistencyLevel $consistencyLevel `
- EnableAutomaticFailover:$true

$database = New-AzCosmosDBSqlDatabase -ParentObject $account -Name $databaseName

$uniqueKey = New-AzCosmosDBSqlUniqueKey -Path $uniqueKeyPath
$uniqueKeyPolicy = New-AzCosmosDBSqlUniqueKeyPolicy -UniqueKey $uniqueKey
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

How would you create blob storage with Azure CLI? How would you create a container? What role do you need to be to do so?

A

az storage account create \

- -name  \
- -resource-group  \
- -location  \
- -sku Standard_ZRS \
- -encryption-services blob

Creating a container requires Storage Blob Data Contributor role

az storage container create \

- -account-name  \
- -name  \
- -auth-mode login
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

How would you create a storage account and blob storage with PowerShell?

A
$StorageHT = @{
  ResourceGroupName = $ResourceGroup
  Name              = 'mystorageaccount'
  SkuName           = 'Standard_LRS'
  Location          =  $Location
}
$StorageAccount = New-AzStorageAccount @StorageHT
$Context = $StorageAccount.Context

$ContainerName = ‘quickstartblobs’
New-AzStorageContainer -Name $ContainerName -Context $Context -Permission Blob

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

How would you create an azure key vault with cli?

A

az keyvault create –name “” –resource-group “myResourceGroup” –location “EastUS”

az keyvault set-policy –name myKeyVault –object-id –secret-permissions –key-permissions –certificate-permissions

17
Q

What are the keys when creating a managed identity?

A

Having an assign-identity, scope, and role.

18
Q

How would you create an azure CDN through cli?

A
# Create a CDN profile.
az cdn profile create --resource-group MyResourceGroup --name MyCDNProfile --sku Standard_Microsoft
# Create a CDN endpoint.
az cdn endpoint create --resource-group MyResourceGroup --name MyCDNEndpoint --profile-name MyCDNProfile --origin www.contoso.com
19
Q

How would you create an APIM instance using CLI? How about with powershell?

A

CLI
az apim create –name myapim –resource-group myResourceGroup \
–publisher-name Contoso –publisher-email admin@contoso.com \
–no-wait

PowerShell
New-AzApiManagement -Name “myapim” -ResourceGroupName “myResourceGroup” `
-Location “West US” -Organization “Contoso” -AdminEmail “admin@contoso.com”

20
Q

How would you enable event grid and create a custom topic in Azure CLI? How would you subscribe to a custom topic?

A

Enable event grid
az provider register –namespace Microsoft.EventGrid

Create custom topic
topicname=

az eventgrid topic create –name $topicname -l westus2 -g gridResourceGroup

Subscripe to custom topic
endpoint=https://$sitename.azurewebsites.net/api/updates

az eventgrid event-subscription create \

  • -source-resource-id “/subscriptions/{subscription-id}/resourceGroups/{resource-group}/providers/Microsoft.EventGrid/topics/$topicname” \
  • -name demoViewerSub \
  • -endpoint $endpoint
21
Q

How would you create an event hub? What is the order of commands in Azure CLI?

A
# Create an Event Hubs namespace. Specify a name for the Event Hubs namespace.
az eventhubs namespace create --name  --resource-group  -l 
# Create an event hub. Specify a name for the event hub. 
az eventhubs eventhub create --name  --resource-group  --namespace-name
22
Q

How would you create an azure service bus

A

az servicebus namespace create –resource-group ContosoRG –name ContosoSBusNS –location eastus

az servicebus queue create –resource-group ContosoRG –namespace-name ContosoSBusNS –name ContosoOrdersQueue