Hey everyone, let's get real here. I'm not a developer
by trade. I'm into infrastructure and operations stuff. Like many
IT pro folks out there, I rely on PowerShell to
handle deployment automation routines and all that stuff. Today I
want to talk to you about GitHub Copilot. It's an
A I pair coder that can seriously help your PowerShell
coding. It'll help you write code faster and with less
effort. Plus, along the way you're likely to pick up
some new skills.
Now, if you're new to GitHub Copilot, check out my
colleagues video on how you can get started with GitHub
Copilot. In this video we'll explore how Copilot can assist
you in your PowerShell coding. It'll offer live coding suggestions
and prompt slash comment based suggestions. It's like having a
coding buddy right there by your side. Let's dive right
into it and see what GitHub Copilot can do for
us.
As I mentioned, GitHub Co palette can assess your PowerShell
coding in many ways. One of the ways is live
coding, the other is by writing comments in your script.
That's GitHub Co palette can take context from.
And suggest solutions. Now the context that it takes can
come from the code that's already in there, open files
that are in VS Code, also from the title or
the name of the file or the script that I'm
writing. In this case 1.1 example shut down VM dot
PS1. If I go to align 6 and go to
the end of the line that GitHub automatically suggests that
I need to set context and that is proper. So
I'm going to accept that suggestion as it enter and
I will start.
Putting a comment telling it that I need to list
all of the M's, the Vm's, their tags in my
subscriptions that are currently powered on and store that in
a variable and it does gives me a suggestion. However,
that suggestion is not quite right. So I can go
to the command, adjust my command, and then accept the
rest of the suggestion. Now GitHub copilot will anticipate what
my next mood should be.
And taking context from the file name and what's already
in the script will suggest what my next iteration should
be. So in this case to loop through each VM
and shut them down, which is exactly what I'm trying
to do but instead of hitting.
Enter. I will hit Control. Enter. Have a second pane
in my VS Code where GitHub Copilot will synthesize up
to 10 suggestions so I can review them and take
the one that I feel is more appropriate for what
I'm trying to do. So I'm going to accept that
suggestion. It's going to insert the code, and then that
way I'm going to review it and edit it and
change what I need to do. So in this case,
I'm going to check what the tags are for that
VM.
In each loop that's proper, I'll accept that suggestion. And
on the next line I'm also going to ask it
to validate that the VM that I'm shutting down are
only the Vm's with the tag with the value of
non persistent. And it does give me a nice suggestion.
And as you can see when I hover over the
Gray text or the GitHub copilot suggestion, there's a little
pop up at the top that's.
Allows me to either go through all of the suggestions,
if they are more than one, to accept it, or
to accept just one word at a time. Now I
don't need line 22 and 23 anymore, but it automatically
suggests that I if I have an if statement I
should have an L statement. So I've accepted that and
go on. Now reviewing my code I can see that
the stop Azvm is not quite right. I am missing
a parameter so I'm going to go there and.
Insert the resource group name and the variable in that
command. Once I've included that, I can test my code.
So I'm going to hit FF5 to execute my code
and as it's running you can see that it's now
shutting down VM1, now shutting down VM2. While this is
going, I'm going to go to my Azure portal.
Refresh and see that I have a couple of machines
that have a life cycle tag equal persistence. So these
should not be touched. And as this is going, we're
going to go back to my script and it's continuing.
And now as you can tell, VM Live Demo one
and VM learn live VM01 were not shut down because
they were tagged as persistent. Could I have written this
by myself? Absolutely.
Did Copilot help me do it in a much faster
way? Absolutely. To conclude our demo, I want to talk
about the shell, because the shell is a powerful place
and it's one that many system men's like me spend
their days in. But it can take many years of
regular use to become a shell wizard to remember every
commands and tricks, even with the solid proficiency most of
us regularly need to use the Get Help command or
scroll through pages of documentation.
Often time we just simply end up doing a web
search and hopefully finding something that is a relevant answer.
GitHub copilot CLI will allow us to avoid that search
and simply ask how do I do X? How do
I list all the PowerShell files? How do I list
all of the Vms in the terminal interface? All you
need is to use one of the three shell commands
provided by GitHub copilot CLI.
?? Get? And GH? And ask the question. Copilot will
return the command and wait for you to confirm before
running it. Well, that's all I had for you today.
And remember, there might be time when Github Copilot isn't
as helpful as you'd expect. Maybe the context is unclear,
or maybe your solution requires a fresh and new a
unique approach.
However, there are many situation where Copilot can truly be
your productive pair programmer, especially when you provide it with
that extra guidance or context. Just remember when you're using
Copilot or writing code on your own, always test it
thoroughly. If you found this video helpful, I really appreciate
if you could hit that like button, subscribe to the
channel and don't forget the smash that bell. Just stay
updated with new content. Also make sure to check out
the rest.
Of the videos in this series catch you later.