Time
1 hour 43 minutes
Difficulty
Intermediate
CEU/CPE
2

Video Transcription

00:00
Hello, everyone. I'm instructor Gerry Roberts, and this is Power Shell scripting
00:05
in this video. We're gonna learn a bit about scripting. First, we're gonna learn what a script actually is.
00:10
How to script in Power Shell. I s see how to use no pad to script, as have other scripting tools that are available.
00:20
So first of all, what is a script?
00:23
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.
00:43
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.
01:03
Tau Power shell I s C for scripting
01:06
power shell, I see is actually meant to be used for scripting I see actually stands for integrated scripting environment.
01:15
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.
01:30
Put it back. You can change where the script pain is at. So I could say show script pain over the right
01:36
And there it is instead of at the top. I personally like the script paid at the top.
01:42
I feel like it's a little bit easier to read. I also like having the commands
01:48
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.
01:57
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.
02:16
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
02:31
I wrote a script to get some information about the by us.
02:38
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,
02:57
guess what? There is a command that matches there's actually a couple
03:00
so you can go through here. And if you also notice when you put your mouse over it,
03:07
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.
03:25
You can see there
03:30
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
03:45
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
03:55
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
04:08
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
04:25
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
04:32
likely there and clicking there.
04:34
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.
04:43
So what you write,
04:47
you'll notice it down here on your regular power show
04:51
that you get
04:55
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,
05:11
I can go to the directory or down here in regular power shell.
05:15
I can just type in the name of the file, since it's in the same directory that we're working with.
05:23
So I want to open the CPU one
05:27
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,
05:47
and that's pretty much power shell I s C. No. Next you could use note pad for scripting.
05:56
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.
06:06
So what, you would, actually d'oh
06:10
is you go ahead and
06:13
open up. No pad
06:15
here. You can see I created one already.
06:21
And you can see I have a couple pieces of information here for a couple of items, too. Right
06:30
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.
06:47
So what I have here is the file that I already created.
06:51
Now, if I want Thio
06:54
create a brand new when I could open up a new note pad
06:59
and when I do this, I can type in the community I want. So I'm gonna just get
07:09
some information about the computer.
07:12
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.
07:26
I'm gonna get if you reach about the desktop
07:30
format that list to again just because
07:34
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,
07:49
so I'll go ahead and say that when you save it,
07:58
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.
08:09
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
08:20
now, there's nothing you could really do here in note. Pad. If you were to go into your file directory here
08:28
and you'll notice that it has not PS one fewer to right. Click it.
08:33
You can choose Run with Power Shell,
08:37
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,
08:48
you'll notice
08:50
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.
09:00
Look at that. We got information about our desktop,
09:03
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!
09:15
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
09:20
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
09:37
power shell I s C. So it is super useful as well.
09:41
So post assessment time. If you wanted to run a script, you created a note pad. How would you go about doing it?
09:50
Would you find the saved ps one file right click run with power show?
09:54
Would you f five in dope pad?
09:56
Could you go to file and run in no pad or you can't run a script. Created a note pad
10:03
so you can go ahead and pause
10:07
and I'll give you a second to figure it out.
10:11
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.
10:30
So that's it for this video We talked about power shell scripting in power. Shall I S C and no pad?

Up Next

Intro to Powershell Scripting

In this course, you will learn the fundamentals of Microsoft Powershell, which is a popular task automation and configuration management framework. In this course you will learn the basics of the tool, to get started scripting today!

Instructed By

Instructor Profile Image
Gerrianne Roberts
Professor, Network Engineering Technology
Instructor