Azure CLI 101

Starting anything new is always difficult, when I had started with Azure CLI was like foreign language to me. I always felt more comfortable with PowerShell and Portal, but never ever tried to use CLI.

But once I started using it I find it much easier to remember and work on it.

It could be difficult to understand first but as you go ahead with knowing the basics and some simple commands everything starts making sense and it becomes pretty easy to write your own commands for creating or listing resources.

First the official documentation for the Azure CLI is this.

You need to have the storage created for the Bash to work, so if you don’t already have one, it will be created for you once you start the CLI for first time.

The CLI commands start with az then group, subgroup and commands or functions and after everything comes the parameter if you require them in your code.

The most important command that you need to know is –help

We will see how to use –help and write a CLI to create a Storage Account.

None can know every command and parameter, and so comes the –help to rescue.

az --help
az --help output

All the parameters has ‘–‘ in front of it, and any value passed is in plain text without any ” or “”.

Scrolling down a bit and you will see storage. Now lets see what help is there for it.

az storage --help
az storage --help

We can see that account subgroup has the details about storage accounts. Check help for this.

az storage account --help
az storage account --help

We need to create a storage account and this has the create command so lets check help for that too.

az storage account create --help
az storage account create --help

“Create” being a command CLI provides information about all the arguments possible and some examples. Using the above arguments I wrote a simplest query providing the minimum arguments possible.

az storage account create -n testclisa101 -g MSLearn

Once I ran this it provided a JSON output like below:

As per it we have created a storage account now lets verify it’s successful deployment.

az storage account list
SA created

So we have got our storage account created using CLI.. Cheers! 🙂

I hope it helps!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s