Azure - Using Powershell

Introduction

 
In this article, I am going to show how to set up resources to work with Azure using power shell. We will learn basic power shell commands which are required to work with Azure. This article can be used by beginners, intermediates, and professionals.
 
Prerequisite
  • Azure subscription
  • Windows Power shell version 5.1.1
First, we will check which version of Powershell has been installed in your machine using the below command
 
Command
 
Host
 
Azure - Using Powershell
 
If you don’t have version 5.1.1 in your machine, it means you don’t have Windows Management Framework 5.1 installed in your machine. You can download and install the correct version from the below URL. Please select the correct version as per the operating system from the below URL.
 
https://www.microsoft.com/en-us/download/details.aspx?id=54616
 
Also, we should have a NuGet installed on the machine.
 
The below command can be used to install Nuget if not installed
 
Command
 
Install-PackageProvider -Name Nuget -RequiredVersion 2.8.5.201 - force
 
Azure - Using Powershell
 

Tools

 
We can connect and use Azure in various ways using various tools. To work with Microsoft Azure it’s better to know all these tools.
 
Few of these tools are,
  1. Azure Portal
  2. Windows Power shell
  3. Azure Command Line Interface (CLI)
  4. Azure cloud shell – This allowed you to use both Bash and power shell from inside Azure portal.
Here I am going to show, how to connect and use Azure with Window Power shell commands.
 

How to connect Azure using Powershell?

 
Below are the steps we need  to follow to work with a power shell command,
  • Open Window Power shell command line as administrator.
  • First, we need to set execution policies so we can go and install remotely signed packages.
Command
 
Set-ExecutionPolicy RemoteSigned
 
Azure - Using Powershell
  • Once the above settings will be done, we will install all Azure modules required for the current users using the below command.
Command
 
Install-Module -Name Az -AllowClobber -Scope CurrentUser
 
Azure - Using Powershell
  • Once Azure modules are installed, we need to import Az to work with Azure command. Please note that 'Az' is used for Azure. 
Command
 
Import-Module Az verbose 
  • Once modules are imported, we will try to connect the Azure account. Execute the below command.
Command
 
Connect-AzAccount
 
Azure - Using Powershell
 
Once you've logged in with credentials you will see the below image with subscription details like Account, SunscriptionName, TenantId, and Environment.
 
Azure - Using Powershell
 
Let's try to get all resources available with our account.
 
Command
 
Get-AzResourceGroup
 
Azure - Using Powershell
 
Now we will create a new resource group and then check again using commands.
 
Command
 
New-AzResourceGroup -Name RG01 -Location "South Central US" 
 
Azure - Using Powershell
 
Let's try to get all resource groups again to check if the new resource group is created or not.
 
Command
 
Get-AzResourceGroup
 
Azure - Using Powershell
 
You can see in the above image that newly created resource groups have been created.
 
We can execute and achieve any thing using power shell commands. It's not possible to cover all commands in a single article. I will try to publish another article on this soon. 
 
That's all for this article. Hope you enjoyed and learned from this article.