If you are an IT professional and have been tasked to create an Azure VM with Powershell for your company in Azure, then this article is for you. By the end of this blog post, you will have an understanding of what it takes to create an Azure VM with Powershell. You’ll also know how you can use Powershell commands to do so, as well as some best practices for your deployments. Powershell is the scripting language that can use to automate tasks or scripts, including those related to Microsoft products like Windows 10 and Office 365.
What is Azure Powershell?
The Azure PowerShell module is a powerful and efficient way to manage any of Microsoft’s cloud services. With Azure PowerShell, you can create and manage your resources from the comfort of a Windows terminal. You can automate tasks to make them run on their own even when no one is around with easy-to-use scripts that require little or no coding experience!
What is Azure Virtual machine?
Azure virtual machine (VM) is a cloud service available on the Microsoft Azure platform. It allows users to create and run virtual machines in Azure data centers, which provide access to software based on Windows or Linux.
Virtual machines are created within “resource groups”, then connected or networked to storage, blob, and Azure SQL databases.
Virtual machines can be connected directly by using a RDP connection or indirectly with the use of Remote Desktop Services. They can also be accessed via SSH protocol an OpenSSH implementation on Windows 10 Anniversary Edition that doesn’t require third party software installation), or via PowerShell Direct. For older versions of Windows, a VNC console can be connected to the VM.
Let’s Create an Azure VM with Powershell
In this Lab, we’ll first configure Azure Cloud Shell in the Azure portal. After that’s done, you can create a resource group and more using PowerShell!
Azure subscription, create one for free if you don’t have one.
Configure Cloud Shell in the Azure portal.
The Azure Cloud Shell is a free interactive shell that you can use to run the steps in this article. It has common Azure tools preinstalled and configured, so they’ll work with your account out of the box, saving time on repetitive setup tasks. Let’s configure it!!
- Please login to https://portal.azure.com.
- In the Azure portal, open the Azure Cloud Shell by clicking the icon at the top right; see the screenshot below:
- A new session will open at the bottom of the portal page; please select PowerShell when prompted to select Bash or PowerShell
- Next, please click on Create Storage to create a storage account for PowerShell
- Once a storage account is created, PowerShell will launch in the portal.
Congratulations!! You have successfully configured your PowerShell in your AZURE Portal.
Now, let’s create a Resource Group and a VM using PowerShell and explore some more PowerShell commands.
- Please make sure your PowerShell tool is open in Azure Portal, which we just now configured.
- Run the below command to create a new Resource Group:
New-AzResourceGroup -Name thinkcloudlylab -Location “South Central US.”
- After successful completion of the command, you will see the below output:
- To get a list of all resource groups in your Tenant, please run the Get-AzResourceGroup command.
- Now, as you have successfully created the resource group, let’ create a new VM; for that, please run the below command:
New-AzVm -ResourceGroupName ” thinkcloudlylab ” -Name “LAB5VM” -Location “East US” -VirtualNetworkName “myVnet” -SubnetName “mySubnet” -SecurityGroupName “myNSG”
- While running the command, you will be asked for the Username and Password. Give both as you want, and wait for the command to get completed.
- Once completed, you can check the list of VMs in Tenant using the below command: Get-AzVM.
- You can validate the same by searching Virtual machines in All services in the portal and clicking on that as shown below:
Please delete or Deallocate VMs after testing to avoid excessive bills.
To deallocate VM using PowerShell run command:
Stop-AzVM -Name LAB5VM -ResourceGroupName THINKCLOUDLYLAB
By the time you are done reading this article, we hope that you feel empowered and confident in your ability to create a VM on Azure. If not, please let us know what topics or questions need more explanation by leaving a comment. We will do our best to help you get started with as little difficulty as possible.