Azure CLI and Powershell Cmds Flashcards
What is the first CLI command you’ll most likely have to do?
Create a resource group
az group create –name {name} –location eastus
How do you create a virtual machine in Azure CLI?
az vm create –resource-group
- -name
- -image
- -generate-ssh-keys
- -output json
- -verbose
How do you show information about a resource?
az {resourceQuery (such as vm)} show –name
–query
How would you create a VM in powershell?
New-AzResourceGroup -Name 'name' -Location 'westus2' New-AzVm - ResourceGroupName -Name -Location -VirtualNetworkName
What fields do you need for an ARM template deploying a vm resource?
adminUsername adminPassword dnsLabelPrefix publicIpName publicIpSku OSVersion vmSize Location vmName
How would you create an azure container instance?
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 would you create an azure container registry?
How about logging in?
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
What are the steps to create and deploy a web app using web app services?
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 do you deploy code to a webapp using CLI?
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 would you deploy deployment slots with azure cli?
# 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 would you deploy a function app?
az functionapp create –name –resource-group –storage-account
func azure functionapp publish
How would you create a Cosmos DB With Azure CLI?
# 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 would you create a Cosmos DB with Powershell?
$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 would you create blob storage with Azure CLI? How would you create a container? What role do you need to be to do so?
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 would you create a storage account and blob storage with PowerShell?
$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