Azure Command Line Tutorial

Video Activity
Join over 3 million cybersecurity professionals advancing their career
Sign up with

Already have an account? Sign In »

23 hours 16 minutes
Video Transcription
Hello and welcome back to Siberia's Microsoft Azure Administrator. A Z 103 course. This is Episode five as your command line tutorial, and I'm your instructor, Will Carlson.
In today's episode, we're going to do just that. We're gonna jump into the command line here for Azure, and we're gonna work through an example to give you some ideas of how the azure command line operates. A CE faras power shells concern regarding variable assignment and command Let's and
the whole nine yards here in Power Shell Now My goal for this episode is not to make you a power shell expert. It's not even to make you an azure power shell expert. It's simply too
familiarize you with power shell and azure deployments so that you can understand the documentation that you should be reading through. As you go throughout this course again,
as we do a concept here within portal, I recommend you looking into the way to get that same goal accomplished. So, for example, deploying a virtual machine once you know how to do that in portal, you should know how to do that and what commands you're likely to see to accomplish. Deploying a virtual machine
via the command line as well. So, again,
the goal for the episode today is familiarity and understanding. In order to get started, we're actually going to jump into a text document that I've created here of the commands to deploy a virtual machine in power shell for Azure.
And to get started here, you'll notice that the first line here is gonna have a pound sign. And that's gonna be a comment here in Azure. And this is just gonna let you know that this command is going to create a resource group.
Now, the first thing you're gonna see here is dollar sign our Jeanne name,
and this is a variable assignment in power. Shell variables are preceded with the dollar signs symbol.
And then we've assigned this variable a value of test dash R G.
We've also created a location variable and assigned its central us. And now you'll see the first command let that we're calling here and power show and a command. Let's simply going to be a command that asks for a number of inputs to accomplish something here in Azure. And the first command like that we've run is new
ese resource group
should be pretty self explanatory here that this is going to create a resource group in Azure.
We have to send in a name parameter and the name is going to be RG name, which we set up here The top now I could have simply put test dash R G right here instead of the variable declaration Elderson RG name.
But doing it with a variable is good for all the reasons that variables air typically good programmatically is I can call dollar sign RG name anywhere in this script or in my power shell session and it will know what I'm talking about. I don't have to re type test dash R G
to create a resource group using the command line. I also have to pass in a location or a region, and we set that using the dollar sign location variable here as well.
Now I want to point out that you can. These little back tick marks here are simply a way of making a command in portal multi line. So portal understands that that means there's going to be a more of the command coming on the next line. You very well could write this entire command just as this down here,
all on one line.
I've gone through here and separated these out in multi lines so you can see what the parameters are and have a better understanding of each one of the command leads. But suffice it to say if we come in here
and we can copy this entire all of this actually, this entire section here, we're gonna copy this. We're gonna go over here into the portal.
We're gonna come up here to cloud Shell icon to open up our cloud shell.
Let's pull this up here to make this window a little bit larger for this episode, and then I'm gonna right click, and I'm gonna paste that command here in
and one interesting. When you paste commands here into the cloud shell, you have to hit Enter on the last command to make sure that completes.
Now, that wasn't so important because that was a comment. But what you can see has been done. Is each one of these lines has been entered into the cloud shell, followed by an enter, which that's what was in our
text editor. And we've created a resource group called Test Dash R G
Again. There's a couple of important pieces here, and these are gonna show up in pretty much every command letter, everything that you try to do here in
the cloud shell or the command line on Azure. And that's gonna be the concept again of variables, dollar signs and command. Let's actually the command that we're going to run in all of the switches that follow it. So the dash name and dash location.
One other thing I want to point out about variables here in power Shell in particular is that when you call the variable so down here in the command lit when we're using the variable, we still have to use the dollar sign notation.
And that's really the basics here of
as your command. Let's in power shell for the command line of Azure, so all we've done right now is create a resource group that was a relatively simple command. Let's look now instead at creating a virtual network and its sub nets. No, again, this will make more sense is the course goes along, but a virtual network is going to be a big container,
and that big container is gonna be divided into smaller containers, which would be the sub nets. So
the first thing I've done here when creating this virtual network via command line is I've set a variable called sub nets and I'm setting that equal to an empty array. That's what this at symbol and the Empty Perrin diseases for an Array is simply gonna hold more than one variable.
I'm gonna head and I'm declared my first sub net name, my second sub net name.
I've also set the 1st 7 at address space. Tim got 0.0 slash 24 the 2nd 7 address space of 10.0 dot one, not zero slash 24. And again, those air the smaller containers here,
a larger container is going to be the virtual network. So it's address space has to be inclusive of these to address spaces. Now, if you don't do this correctly, your power shell will error out here.
But I've done that correctly here, so we have a 10.0 slash 16 which is inclusive of these 27 minutes. So that Z that suffice to set up my sub nets and their I p ranges and also the i p range of my virtual network.
I've given my virtual network and name here and again. This is all just by variable. I'm just setting the variables for the pieces that I'm goingto ultimately need when I call the command line.
Now, one interesting thing here with a raises. This array of sub nets is currently empty. So I have to assign the sub net values to the sub nets array. And I do that using the plus equals operator.
So we set the sub nets array equal to new ese virtual network sub net convict. And this in itself is a command lit. And
what it's doing clearly is creating a virtual sub net and in order to call this command, But I have to pass a name
which were doing here first sub net name.
And then I also have to pass in the seventh at I P Range,
which I'm doing here again. This is just referencing the variables up here that we created. I'll do that for both sub nets, and all that did was put both of these sub nets the first and second sub net and to the sub nets array.
Now I'm ready to actually create my virtual network, and you'll notice that instead of just calling the command lit, I actually assign the value that's returned to a variable of V. Net. And the purpose of doing this is so again that I can call the virtual network by variable later on in the script
instead of having to look up the I d for the virtual network later on.
It's a good idea to call the command lit and assign it to a variable if it's something that you're going to be needing later on in your scripting.
The command lit to create a new network is new dash ese virtual network, and I've called that here,
and there are a number of switches that have to be set as well. We have to pass a name.
We have to pass the resource group that it's gonna be a part of. So again you can see this resource group Variable comes all the way from the very first command lit that we ran today.
The location is also another one that we used previously,
and then we have to pass in the address prefix and the sub nets array as well, and you'll notice that I made a little bit of an error here on my formatting. So we'll go ahead and fix that while we're here. So that makes a little more sense. Clean this up a bit and there were good to go. So there were a number more switches that had to be passed in here for
configuring a virtual network for the new ese Virtual Network command.
But once I pass all those in, that creates the virtual network.
So so far from this point to this point, we've created a resource group, and we've also created a virtual network. So let's go into power, show real quickly and do this part as well.
Come over here. You can right click and select paste.
It's gonna execute all those commands as we go. Now you're probably wondering what this yellow text is, and that's simply as you're letting me know that some things in the command let are going to be changing,
and it's making sure that I'm aware of those things so that these commands don't break in the future. None of these are a problem for us today. and remember, I've got a hit Enter here on the last command to complete that execution. And now that's completed. And you'll notice that that took a little bit of time and it looked like things were hung up.
That's just by nature of the way power shell deployment works here in Azure. So give it some time. It will ultimately complete.
Now here. Since we're in Portal, let's scroll this down a little bit and let's go into resource groups. Just validate that. We're actually getting something done and I can see my test RG right here, which is the one that we created. And I can see my test Vina that we just created be a power show.
Let's pull this back up back over to our text editor
very quickly. Here, tow. Walk through the rest of this
I have to set the VM size So the size of the virtual machine that I'm gonna deploy on in this case, it's standard d s to be, too.
I'm gonna name my VM and then I'm gonna call set this variable dollar sign B m by calling the command let new ese vm convict
clearly were setting up the configuration for a new virtual machine. The next thing we're gonna do when deploying a virtual machine is set up the operating system some basics about the operating system
and primarily here. We're gonna have to set some credentials and you'll see what this does when we go back into power Shell. But I'm gonna call, get credential
and I'm gonna pass that in. So Windows has some credentials and you'll notice that I'm passing back into this command lit
dollars on B M that I sat just up here.
Once we've done that when deploying a virtual machine, we also have to set up the operating system image.
We're going to deploy a Windows 2016 Data Center server, and we have to set a number of other things here to make that work. But primarily what we're setting here is the name of the operating system publisher, which is Microsoft. The offer name, which would be Windows server in this case Windows desktop, would be another option here or Lennox desktop a bun, too.
And we set the skew so this could be 2019 data center. But in this case, it's going to be 2016
And then we call set a Z V m source image with the switches that we just set.
And then we also have to create an operating system disk. Now, in this example, we are creating a managed disk. If you didn't want to do that, the switch here would be different. But we're gonna be using manage storage for this virtual machine, which is typically how you'll deploy a virtual machine.
We also have to create a network interface card on a virtual machine. And we've done that here very simply.
And then last step here would be actually the command to provisioned the virtual machine. I'm gonna go ahead and copy and paste all the parts that we haven't done so far. Just all the way back up here to set the M size.
We're gonna copy this over,
jump right back into portal
right click paste.
And this deployment is gonna go ahead and finish. Now, this section right here is what I was talking about about get credentials. You have to put in your user name and password
to go ahead and finish setting up that virtual machine.
And so far, we're going along great.
Our story has been created, a virtual network has been created, and now we're actually on the very last step again. We have to select inter here to go ahead and deploy this virtual machine just because of the nature of copy paste.
And this step is going to take some time. And that's really all there is to using power shell here with azure, it seems, honestly a little bit toe insincere to say that's all there is to it. Power shell and azure is a very powerful tool. I recommend spending some time getting familiar with it
again. For a Z 103 You're not goingto have to be able to
run commands and create them from scratch. You absolutely will not be asked to deploy a virtual machine from start to finish
on a Z one of three. What you will be required to do is be given a couple of different commands that summer. Correct. One is obviously correct and the others are wrong, and you'll be asked which of these commands would be used to deploy a virtual machine and azure using power shell,
and you'll need to know the difference again. Go back to the previous video that talks about some simple tips and tricks and getting familiar with commands here
in power, shell or azure. But what I wanted to do in this video was give you an idea about variable declaration how you can reuse them and give you a template to come back to as you go forward and help you understand. Power shell and azure. Now
down below. In the resource is tab, you will find a link to all the text that I used to deploy this virtual machine. In this episode, I recommend you stepping through it and making sure you understand each of the commands in the command line interface in the text document created down below.
Coming up next, we're going to finally get into the heart of what Azure is, and we're gonna begin talking about Azure Resource Manager, which is the way that resource is our deployed here in Azure and some of the great ways that it helps us automate things versus a previous deployment method used in a measure.
Thanks so much for joining me for this episode. I'm looking forward to the next one
Up Next
AZ-103 Microsoft Azure Administrator

This Microsoft Azure AZ-103 Certification training course teaches students to perform tasks like managing Azure subscriptions and resources, implementing and managing storage, deploying and managing virtual machines (VM) and networks, and managing identities!

Instructed By