1 hour 43 minutes
Hello, everyone. I'm instructor Gerry Roberts, and this is Power Shell scripting
in this video. We're gonna learn a bit about scripting. First, we're gonna learn what a script actually is.
How to script in Power Shell. I s see how to use no pad to script, as have other scripting tools that are available.
So first of all, what is a script?
Script is pretty much just a file with a command or commands that you can run instead of typing. Amount manually. So pretty much what you're doing is you're copying, pasting or typing out your commands until file saving it. So that way, you can run it later. Instead of having to type everything out again, scripts can be run manually or they could be set up to run on a schedule.
Scripts are typically used to automate day to day processes like backups log on, log off scrips, scrips. It'll do things like change your background and change your settings when you look in. Also to be able to gather information about computers and Maur administrative tasks.
Tau Power shell I s C for scripting
power shell, I see is actually meant to be used for scripting I see actually stands for integrated scripting environment.
So this is what power shell I s see, it looks like, um, I have actually already modified some things to add the commands. When don't in the script window, if you go in the top, you can do view and you can actually get rid of this campaign.
Put it back. You can change where the script pain is at. So I could say show script pain over the right
And there it is instead of at the top. I personally like the script paid at the top.
I feel like it's a little bit easier to read. I also like having the commands
add in over here on the right so I can actually look for my commands and then your regular powershell windows actually at the bottom here.
So when working in power Shell, I s C on the script pain. Just this page right here. You'll notice that it's his untitled that p s one. I haven't really done anything with it yet, so there's no name for it. PS one is actually the power shell scripting file format.
So if you write a file in another program and need to save it as a Power Shell script. Remember that it's dot ps one. That's also if you're looking through files and you find one that stop, yes, when you know the power shell script. So here
I wrote a script to get some information about the by us.
So what you do in here is you write your command or commands that you want. So say, for example, I wanted to do more than that and get more information I could do get and then see I am. And you'll notice. The nice thing here is the intelligence tells us. Hey,
guess what? There is a command that matches there's actually a couple
so you can go through here. And if you also notice when you put your mouse over it,
you'll be able to click on it. Or you can just use up and down arrows to choose one. And when you choose one at first, you'll notice you don't get that nice little information kind of like you do with the help command in a regular power show. So once you have the one you want selected, you enter, it will actually complete it for you.
You can see there
and then whatever. I tell you what if you wanted the CPU information, that would be processor and here I'm going to format. It is a list, so it's easier read. So I'm gonna pipe a list
and then I'm going to pipe of file. The 1st 1 has bio to don t x t for the bios. I could call the super you to the
T X t So pipes it to file called CPU to dock T X t Now remember, from our piping to final lesson If we pipe anything to ah file, the file doesn't have to exist. If it
does not exist yet, what it'll dio is it will actually create the file for you. So once you have your script written, there a couple ways to run up here, you notice that you have a little play button
and then you can also select part of it and just play the part of that you want. So for example, I could just run that
likely there and clicking there.
If you want to run the whole thing, you could do the run could also go to file and run or you can just do F five to run it.
So what you write,
you'll notice it down here on your regular power show
that you get
a little bit of output. You see that it ran up and around that you won't get much usually unless there's an air. If there's an aerial, get a big old wall of red text. Otherwise it'll show that it ran it. Now, if I want to actually open up the file,
I can go to the directory or down here in regular power shell.
I can just type in the name of the file, since it's in the same directory that we're working with.
So I want to open the CPU one
and notice that it opens for me. Now, notice that this script created the file for me and it gave me the information for the steep E, which is pretty cool. Now. You can see this could be super useful if you're working with computers that need to get information about them,
and that's pretty much power shell I s C. No. Next you could use note pad for scripting.
So some people they don't necessarily want the whole interface. They just want to write their script. And that's it. And that's fine. You can do that. No, Pat.
So what, you would, actually d'oh
is you go ahead and
open up. No pad
here. You can see I created one already.
And you can see I have a couple pieces of information here for a couple of items, too. Right
now, one thing you'll notice is that obviously in no pad, you're not going to get intel a sense you're not gonna get auto complaint. You're not gonna get all the fancy pretty things you do in Iasi. But this is great for if you just want to do quick and dirty power show script and your guy.
So what I have here is the file that I already created.
Now, if I want Thio
create a brand new when I could open up a new note pad
and when I do this, I can type in the community I want. So I'm gonna just get
some information about the computer.
It again You noticed that there's no Intel essence. So any typos I do or anything like that? I have to go back and fix.
I'm gonna get if you reach about the desktop
format that list to again just because
I want to make sure that it's easy to read and then I can actually output it toe file, too. So you'll see here I have a script that's going to get information about the Win 32 desktop,
so I'll go ahead and say that when you save it,
you'll notice that it normally goes to tax. You are cheated all files so you could save it as a proper. And I'm gonna say this as my test script.
Two p s. One. Remember, when you say that you have to put a dot PS one so it knows it's a power show file and save it
now, there's nothing you could really do here in note. Pad. If you were to go into your file directory here
and you'll notice that it has not PS one fewer to right. Click it.
You can choose Run with Power Shell,
and it'll run Now The power show will pop up and disappear pretty quickly. Might not have even seen it, but once it's run,
we get this new file desktop to dot t X T which was the file, if you remember looking at our powershell script that we're piping too.
Look at that. We got information about our desktop,
so it's a little more complicated with no pad because you actually have to go find the file, run it and all that good stuff. But you can still do scripting in note pad if that's what you want to. D'oh!
So we looked at Power Shell I s C. We looked at note pad, but there are a couple other tools that you can use
Ah, we have no pad plus plus, which allows you to color code your commands so you can easily see what you're doing. You also a visual studio that will also automatically color code your commands Visual studio does have some intelligence items in it, like
power shell I s C. So it is super useful as well.
So post assessment time. If you wanted to run a script, you created a note pad. How would you go about doing it?
Would you find the saved ps one file right click run with power show?
Would you f five in dope pad?
Could you go to file and run in no pad or you can't run a script. Created a note pad
so you can go ahead and pause
and I'll give you a second to figure it out.
All right. The answer's a You'd find the same PS one file and right click run with power Shell B and C are used for power Shell I S C and D is incorrect. You totally can create a scripted no pad. Save it and run it later.
So that's it for this video We talked about power shell scripting in power. Shall I S C and no pad?
Create Scheduled Jobs with Windows PowerShell
The Create Scheduled Jobs with Windows PowerShell Guided IT pro Challenge from Learn on Demand ...
Learn On Demand
This Azure Automation IT Pro Challenge helps learners understand how to use the Azure Portal ...
Learn On Demand