Time
23 hours 16 minutes
Difficulty
Intermediate
CEU/CPE
7

Video Transcription

00:00
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.
00:11
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
00:29
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
00:39
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,
00:51
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
01:10
via the command line as well. So, again,
01:12
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.
01:29
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.
01:42
Now, the first thing you're gonna see here is dollar sign our Jeanne name,
01:48
and this is a variable assignment in power. Shell variables are preceded with the dollar signs symbol.
01:55
And then we've assigned this variable a value of test dash R G.
01:59
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
02:17
ese resource group
02:20
should be pretty self explanatory here that this is going to create a resource group in Azure.
02:25
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.
02:39
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
02:57
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.
03:07
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,
03:24
all on one line.
03:27
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
03:37
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.
03:46
We're gonna come up here to cloud Shell icon to open up our cloud shell.
03:52
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
04:00
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.
04:08
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
04:19
text editor. And we've created a resource group called Test Dash R G
04:28
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
04:34
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.
04:49
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.
05:01
And that's really the basics here of
05:05
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,
05:26
and that big container is gonna be divided into smaller containers, which would be the sub nets. So
05:30
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.
05:48
I'm gonna head and I'm declared my first sub net name, my second sub net name.
05:54
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,
06:08
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.
06:20
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.
06:35
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.
06:46
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.
07:00
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
07:09
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
07:15
which were doing here first sub net name.
07:18
And then I also have to pass in the seventh at I P Range,
07:23
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.
07:36
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
07:56
instead of having to look up the I d for the virtual network later on.
08:01
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.
08:09
The command lit to create a new network is new dash ese virtual network, and I've called that here,
08:16
and there are a number of switches that have to be set as well. We have to pass a name.
08:22
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.
08:31
The location is also another one that we used previously,
08:35
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
08:56
configuring a virtual network for the new ese Virtual Network command.
09:00
But once I pass all those in, that creates the virtual network.
09:05
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.
09:16
Come over here. You can right click and select paste.
09:20
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,
09:30
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.
09:46
That's just by nature of the way power shell deployment works here in Azure. So give it some time. It will ultimately complete.
09:52
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.
10:07
Let's pull this back up back over to our text editor
10:11
very quickly. Here, tow. Walk through the rest of this
10:15
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.
10:22
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
10:33
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
10:45
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
10:52
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
11:00
dollars on B M that I sat just up here.
11:03
Once we've done that when deploying a virtual machine, we also have to set up the operating system image.
11:09
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.
11:30
And we set the skew so this could be 2019 data center. But in this case, it's going to be 2016
11:35
And then we call set a Z V m source image with the switches that we just set.
11:43
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.
11:58
We also have to create a network interface card on a virtual machine. And we've done that here very simply.
12:05
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.
12:16
We're gonna copy this over,
12:18
jump right back into portal
12:20
right click paste.
12:24
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
12:35
to go ahead and finish setting up that virtual machine.
12:37
And so far, we're going along great.
12:41
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.
12:52
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
13:11
again. For a Z 103 You're not goingto have to be able to
13:15
run commands and create them from scratch. You absolutely will not be asked to deploy a virtual machine from start to finish
13:24
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,
13:41
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
13:48
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
14:03
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.
14:18
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.
14:37
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 is a training course for the Microsoft Azure AZ-103 Certification. The Microsoft Azure Administrator 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

Instructor Profile Image
Will Carlson
Director of IT and Cybersecurity
Senior Instructor