Learn about Windows PowerShell
Hey, Scripting Guy! Your Windows PowerShell articles have been real interesting, and I have been fascinated by the things you can do. But I need you to start at the beginning. It all looks real confusing to me. How about it? - TD
You know things are only confusing when you do not understand them. We remember very well the first time we downloaded and installed Windows PowerShell. We also remember a painful couple of weeks spent with our heads down over the computer console trying to figure things out back when there were no books written on the subject and the product was still in beta, and even the Help files were incomplete. Ed remembers very well his first thought after installing Windows PowerShell: "Dude, this is different."
This week we will be looking at the basics of Windows PowerShell. Windows PowerShell is installed by default on Windows 7 and Windows Server 2008 R2. It is an optional installation on Windows Server 2008 and a download for Windows Vista, Windows XP, and Windows Server 2003. The Windows PowerShell Scripting Hub is a good place to get started with Windows PowerShell.
So what is Windows PowerShell? For people who come from a Windows background, Windows PowerShell will take some getting used to because it provides a new kind of capability to the environment. On the one hand, there is the Windows PowerShell console that enables you to type commands in an interactive manner. On the other hand, it is a scripting language that lets you write scripts. It is similar to taking the command prompt and putting VBScript inside it. You get two tools in one. It is like a chocolate bar with almonds in it: You get both chocolate and nuts.
The heart of Windows PowerShell is the cmdlets that are included with the product. These cmdlets are built into Windows PowerShell, but can also be written by other people to provide additional capability. Let's open Windows PowerShell, and get information about all the processes running on our computer. The Get-Process cmdlet returns information about the process ID, how much CPU time is being consumed, and memory consumption. The cmdlet is Get-Process, and the results are seen here:
If we are interested in services, the Windows PowerShell cmdlet is Get-Service. When we run this cmdlet, we get information about the service name, status, and display name. The results are shown here:
If we want to get the date, the cmdlet is Get-Date, and if we want the culture settings on the computer, we use Get-Culture. But we are not limited to just using Windows PowerShell cmdlets within the Windows PowerShell console. We can also use external commands such as getmac.exe. This is shown here:
To this point, all of our cmdlets have begun with the word Get and have been followed by another word. All Windows PowerShell cmdlet names are made up of two parts. The first part of the cmdlet name is called a verb, and the second part of the cmdlet name is called a noun. These are not strictly grammatical in definition. But the idea can be summarized as follows: "What do you want to do, and what do you want to do it to?" A standard set of verbs makes it easy to remember the cmdlet name. As an example, a common task by network administrators is to stop a process. Many different utilities require us to remember to stop, unload, delete, kill, terminate, or some other permutation of ending a process. In Windows PowerShell it is easy—the verb is always Stop. If you want to start something; you use the Start verb. A listing of the verbs from Windows PowerShell 1.0 is seen in Table 1.
You can also use Windows PowerShell in ways that are already familiar to you. For example, if you want to get a directory listing, you can type dir as shown here:
To create a directory, you can use the md command and tell it the name of the directory you want to create. As soon as a directory is created, you can create a text file by using the redirection arrows to capture the results of a command such as the dir command that was used earlier. This is shown here:
The text file that was created in the previous command is shown here:
The last thing you might want to do is delete a text file and a folder. To do this, you use the del command to delete a file. The first thing that you might want to do is to change your working directory to the c:\hsgTest folder that was created earlier. To do this, you use a command that is familiar to you: the cd command. As soon as you are in the directory, you may want to get another directory listing by using the dir command. Next, you use the del command to delete the directory.txt file. As shown in the following image, the file name is preceded by a ".\" character. This means that you are interested in the file in the current directory. When you type the first couple of letters of the file name and press the tab key, the ".\" is automatically added to the file name in addition to expanding to the complete file name. This enables you to avoid typing the complete file name. The feature is known as tab expansion.
Well, TD, as you can see, working with Windows PowerShell can be as easy as working at the command prompt. We hope that you have enjoyed this introduction. Join us tomorrow as Windows PowerShell Basics Week continues. Until then, peace.
Ed Wilson and Craig Liebendorfer, Scripting Guys
Why there no Pictures between the Text????
my first course here and I like it :)
Thumbs Up, Well Done
i like it. it is writen here very simple so that it´s good to understand. thx.
Very good, it reminds me on the Commandset of dos x.xx
Ok, nice! Next one please.
it is easy understandable for people who aren't good in english