Azure Hands-On Labs - Creating VMs using PowerShell

Azure Hands-On Labs - Creating VMs using PowerShell

Azure Learning Path for Cloud and DevOps Engineers

📝Introduction

This post demonstrates this hands-on lab, where we walk through using Azure PowerShell to create a VM. This is a beginner-level and it covers several concepts, including the following.

  • Creating an Azure virtual machine with PowerShell.

  • Obtaining the public IP address of the virtual machine.

  • Logging into the virtual machine via remote desktop.

This hands-on lab uses the Azure Cloud Shell, so there's no need to install any software if you prefer.

📝Log in to the Azure Management Console

Using your credentials, make sure you're using the right Region. In my case, I am using west-us.

📌Note: You can also use the VSCode tool or from your local PowerShell to connect to Azure PowerShell

More information on how to set up it is on the link.

📝Prerequisites:

  • Update to PowerShell 5.1, if needed.

  • Install .NET Framework 4.7.2 or later.

  • VisualCode

  • Web Browser (Chrome, Edge)

📝Create an Azure Virtual Machine

  • Click the Cloud Shell icon (>_) at the top of the page.

  • Click PowerShell.

  • Click Show Advanced Settings. Use the combo box under Cloud Shell region to select the Region. Under Resource group and Storage account(It's a globally unique name), enter a name for both. In the box under File share, enter a name. Click ***Create storage (***if you don't have any yet).

  • Get the name of the Resource Group.

      Get-AzResourceGroup
      #Copy the value for the ResourceGroupName parameter to the clipboard.
    

📌Note - In this hands-on, I prefer to use the VSCode logged in my Azure Account to run the commands.

  • Create the new virtual machine with the following parameters. For RESOURCE_GROUP_NAME, paste in the name copied in the previous step.

      new-azvm -ResourceGroupName 'RESOURCE_GROUP_NAME' `
      -Name 'TestVM' `
      -VirtualNetworkName 'DemoVNet' `
      -SubnetName 'DemoSubnet' `
      -SecurityGroupName 'DemoSG' `
      -PublicIpAddressName 'DemoPubIP' `
      -OpenPorts 80,3389
    
      #Provide a username when prompted and provide a password.
    

    You can also check on the Azure Management Console the resources created.

  • Obtain the Public IP Address:

Get-AzPublicIpAddress

📝Connect to VM using RDP

The previous VM created is a Windows Server OS, so we can test if the RDP access(allowing port 3389 during the creation of the VM) is working using the Public IP directly from our computer.

  • Open the PowerShell terminal in your computer and follow the command:

      mstsc /v:<public IP>
    

📌Note - At the end of each hands-on Lab, always clean up all the resources previously created to avoid being charged.

Congratulations — you have completed this hands-on lab covering the basics of Azure PowerShell and how to create a VM resource using this tool.

Thank you for reading. I hope you understood and learned something helpful from my blog.

Please follow me on CloudDevOpsToLearn and LinkedIn franciscojblsouza