Skip to content

Instantly share code, notes, and snippets.

@rupeshtiwari
Last active September 5, 2021 23:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rupeshtiwari/080b01ced54b771de1b549ad47f87a35 to your computer and use it in GitHub Desktop.
Save rupeshtiwari/080b01ced54b771de1b549ad47f87a35 to your computer and use it in GitHub Desktop.
azure lab az-104

AZ-104 Labs (Azure Adminstrator Associate Labs)

Creating 3 Linux VMs using Powershell Script

If you create manually 3 VMs from the Azure Portal it will take longer. Now you write a powershell script that you can reuse to create 3 VMs automatically to any resource group provided by the user.

Lab link: https://docs.microsoft.com/en-us/learn/modules/automate-azure-tasks-with-powershell/8-exercise-create-resource-using-script

# conferencedailyreset.ps1

param([string]$resourcegroup) 

$admincredential = get-credential -message "Enter the username password for VM administrator"
for($i=1; $i -le 3; $i++) {
    $vmname = "ConferenceDemo"+$i
    write-host "Creating VM:" $vmname
    new-azvm -resourcegroup $resourcegroup -name $vmname -credential $admincredential -image UbuntuLTS
}

# Execute script 

./conferencedailyreset.ps1 learn-fac3d57e-c810-40b0-89b6-ad4512b2e6ad

# View VMs

Get-AzResource -ResourceType Microsoft.Compute/virtualMachines

Create an Azure website using the Azure CLI & deploy code from GitHub

export RESOURCE_GROUP=learn-4e18e730-c221-430b-bc4e-6feac0b20082
export AZURE_REGION=centralus
export AZURE_APP_PLAN=popupappplan-$RANDOM
export AZURE_WEB_APP=popupwebapp-$RANDOM

# Create app service plan
az appservice plan create --name $AZURE_APP_PLAN --resource-group $RESOURCE_GROUP --location $AZURE_REGION --sku FREE

# Create Web App
az webapp create --name $AZURE_WEB_APP --resource-group $RESOURCE_GROUP --plan $AZURE_APP_PLAN

# Access Web app  
curl $AZURE_WEB_APP.azurewebsites.net

# Deploy Source Code from GitHub to our Web App
az webapp deployment source config --name $AZURE_WEB_APP --resource-group $RESOURCE_GROUP --repo-url "https://github.com/Azure-Samples/php-docs-hello-world" --branch master --manual-integration

# Access site again 
curl $AZURE_WEB_APP.azurewebsites.net
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment