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.
First, we will check which version of Powershell has been installed in your machine using the below command
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
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,
- Azure Portal
- Windows Power shell
- Azure Command Line Interface (CLI)
- 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
- 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
- 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
Once you've logged in with credentials you will see the below image with subscription details like Account, SunscriptionName, TenantId, and Environment.
Let's try to get all resources available with our account.
Command
Get-AzResourceGroup
Now we will create a new resource group and then check again using commands.
Command
New-AzResourceGroup -Name RG01 -Location "South Central US"
Let's try to get all resource groups again to check if the new resource group is created or not.
Command
Get-AzResourceGroup
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.