Home
Username:
Password:
Microsoft Windows Server 2008 Tutorials

PowerShell / Scripts




Visitors to VTC.com will be able to view all introductory videos for each training course.
Free Trial Members will gain access to first three chapters for each training course.
Full Access Members have full access to VTC.com’s entire library of video tutorials.


Learn More

Subtitles of the Movie

Now I want to take you through a little demo here of exactly how to get PowerShell working and how to kind of introduce yourself to some of the scripts. Now, keep in mind, the way we're going to use PowerShell, it depends on what exactly you want to do. If I click on Start and choose PowerShell, I can also go to All Programs and choose PowerShell. Notice that when PowerShell comes up, there's a lot going on here. I can issue any DOS command and right here from the command prompt. I can even invoke and I can use the Alias II for that and notice I can type Calc.exe and oh, I need to put the path. There we go. And I can kick off calculator. OK? I could even leave the II off of there and do that as well. OK? But notice I can type, for example, Notepad and it will open Notepad for me. So this is very, very similar to the DOS prompt, but now let's go a step further. I want to run some scripts and so what I'm going to do, I'm going to minimize this for now and I'll show you the easy way to get started with this thing and it is a lot different, it's a little bit funky compared to what you've ever done, even if you've done programming. So I want to kind of give you a quick tutorial here. The first thing I'm going to suggest you do is go out to Microsoft's web site. OK? And when you get there, you have pardon me scrolling. My resolution is an issue here. But I'm going to do a search for, you guessed it, PowerShell. And what I'm going to do when this comes back, well, Bill's protecting me from the ills of the Internet. OK. Scripting with PowerShell, if I, I'll take that link and go look around. What I want to get you to is something that's called, notice here's a Home Page, Free Books, Courseware, Tool Box, here's the PowerShell Owner's Manual and if you go out to that, notice they give you all kinds of things. I do want to show you shortcut keys. Now the shortcut keys, and these are very similar to the ones that you see in the DOS world, you know, you can move up and down through your password history, you know, page up and page down displays the first page in the command history, the last one and then, of course, the way we actually get the command history going is if I hit F3. OK? This will display my previous command, this is the same thing as hitting the up arrow key once. So anyway, you've got the same shortcut keys that you have out there in DOS. So you can go look at those. But you need to read Getting Started with Windows PowerShell. OK? Let me scroll this over. And you need to read Running Windows PowerShell Scripts. OK? Because this is more, like you're saying here, just the Command Console. You can actually execute scripts and I want to show you, give you a quick tutorial on how to do that. The first thing I did, and I wish I hadn't of closed that, but I went out to the Site and I looked up some sample scripts and I found one. And so what I did was I came out here to My Computer and on the C drive I just created a little folder called Scripts and I created one called SCuts. OK? And notice I just dropped this, copied it into a Notepad and I want to show you just a little bit about what's going on. Anytime you see a dollar sign, that is a variable in PowerShell and so we created a variable called STR Computer or Strain Computer and we've set it equal to the period which means this one. This computer the script's running on. I could have put the NetBIOS name of another computer or an IP Address, but then I set up one called Column Items and this is kind of like a collection, if you will, in the .NET Framework world and setting that equal to and I'm calling the Get-WMIObject, the class name, I'm putting the name space that it's in and then the Computer Name, which is the computer that we're on because we're taking whatever's located in here and dropping it in here. Then we're doing a foreach loop. OK? For every one of the COL items right here, in the Object item, we're basically creating Object item right here, for each Object item in the collection of items, then we're going to write out something. Ok? But notice what we've actually done is we have, we're going to read the Object item and when we call it, it's basically built on this class, the Win32 product, and we're calling Object item description, so we're reading the description property, the identifying number property, the install date property and we're just listing those out. Write host, this is what writes information out line by line. So what I'm going to do now is execute this script and I want to show you what it looks like. So I'm going to close this out. I will open my Windows PowerShell environment and now this is something kind of interesting. OK? I can go to this, and this is a gotcha that will drive you nuts. I can go to my Scripts folder and if I type SCUTS.ps1 and I gave it a, it's a PS1 extension, notice it says I don't recommend that. I can't, I don't see that. I can't run that. Now, if I do a directory here, right there it is. But this is just one of the quirks of PowerShell and that is I have to always give it the full directory address. And now my script will run. It will take it a second to kind of loop through the thing, compile it up and notice, here comes the data. Now, what this one is doing is getting every one of the applications on the computer and let's just look at one here. Notice the caption? Microsoft Office Proof. This is the Spanish version. Here's the identifying number. Here's the installation date; 4-14-2008. The location, here's where it's located. OK? Here's the package cache, here's the vendor and here's the version number. So if I come on down to Silverlight, Silverlight was loaded 5-8-2008 and so forth. Here's the package cache where it came from and so forth. Real general idea to show you how to, if nothing else, go out and grab scripts off the web site, copy them into Notepad, make it a .psi file. Pay attention to where you put it on your hard disk and then go call them out of PowerShell. OK? Very quick, dirty introduction. You got a lot to learn, so get busy.

Tutorial Information

Course: Microsoft Windows Server 2008
Author: Mark Long
SKU: 33911
ISBN: 1-934743-96-8
Release Date: 2008-09-10
Duration: 6.5 hrs / 70 lessons
Captions: Available on CD and Online University
Compatibility: Vista/XP/2000, OS X, Linux
QuickTime 7, Flash 8

VTC Sign up & Benefits

  • Unlimited Access
  • 98,729 Video Tutorials (23,265 free)
  • Video Available as Flash or QuickTime
  • Over 1026 Courses
  • $30 for One Month Access
  • Multi-User Discounts Available