|This chapter excerpt from Essential PowerShell, by Holger Schwichtenberg, is printed with permission from Addison-Wesley Professional, Copyright 2008.
Click here to purchase the entire book.
WPS 1.0 includes only 129 commandlets. You might ask why I wrote only. You will notice soon that the most important commandlets are those with the verbs get and set. And the number of those commandlets is quite small compared to the large number of objects that Windows operating systems provide. All the other commandlets are, more or less, related to WPS infrastructure (for example, filtering, formatting, and exporting).
PowerShell Community Extensions (PSCX) is an open source project (see Figure 1.11) that provides additional functionality with commandlets such as Get-DhcpServer, Get-DomainController, Get-MountPoint, Get-TerminalSession, Ping-Host, Write-GZip, and many more. Microsoft leads this project, but any .NET software developer is invited to contribute. New versions are published on a regular basis. At the time of this writing, version 1.1.1 is the current stable release.
|DOWNLOAD POWERSHELL COMMUNITY EXTENSIONS|
PSCX is provided as a setup routine that should be installed after WPS has been installed successfully.
You can incorporate additional functionality of PSCX into WPS by using a profile script (see Figure 1.12). Just copy this profile script to your My Documents/Windows PowerShell directory, if you want, during PSCX setup. As a beginner, you should use this option.
Testing the PowerShell Extensions
The installation of PSCX changes the WPS console just a bit. Instead of the current path, the prompt now contains a counter. However, the path does display in the window's title.
Start WPS and type Get-DomainController (if your computer is a member of an Active Directory) or test PSCX by using Ping-Host with any computer on your network (see Figure 1.13).
Downloading and Installing the PowerShellPlus
Unfortunately, Microsoft does not provide a script editor for WPS yet. However, a few third-party editors support WPS (see Chapter 9, "PowerShell Tools"). Throughout this book, we use PowerShellPlus Editor, which is free for noncommercial use.
A previous editor called PowerShell IDE from the same author was free even for commercial use. However, PowerShell IDE never made it to a final release and was discontinued.
The PowerShellPlus Editor is part of PowerShellPlus. PowerShellPlus consists of the editor and a console that provides IntelliSense while using the PowerShell interactively.
|POWERSHELLPLUS WEBSITE www.powershell.com|
PowerShellPlus does not need any setup. It is a true .NET application with XCopy deployment. You just unpack the ZIP file to the directory of your choice and start the PowerShellPlus.exe that is part of the package.
Testing the PowerShell EditorThe PowerShellPlus has, according to the WPS console, two modes: an interactive mode and a script mode (see Figure 1.14). After starting the PowerShellPlus, you will see the interactive mode. You can use any commandlet (or pipeline). When you press Return, the commandlet is executed, and the result displays in the same window. The handy feature is the IntelliSense. If you enter Get-P, you will see a drop-down list of the available commandlets that start with these letters.
To use the PowerShellPlus in script mode, click Code Editor and create a new script file (New/PowerShell Script) or open an existing script PS1 file (Open). Now open the script file CreateUser.ps1 that you created earlier. You will see line numbers, and you will encounter the same IntelliSense features that you have in interactive mode. To run the script, click the Run symbol in the toolbar (see Figure 1.15). The result will display in the interactive Windows in the background.
WARNING Make sure the user account does not exist before running the script. Otherwise the script will fail with the error "The account already exists."
Another great feature is debugging. Place the cursor on any line in your script and click the Debugging icon. Next, go to any line and press F9. This creates a red circle next to that line, called a breakpoint. Now run the script. You will see the PowerShellPlus Editor executing the script in slow motion, marking the current line yellow and stopping at the line with the breakpoint (see Figure 1.16). In the Variables Inspector window, you can inspect the current value of all variables. In the interactive window, you can type any WPS command that will be executed within the current context. That is, you can interactively access all script variables. To continue the script, press F8 or click the Continue icon in the toolbar.
Code snippets are also a nice feature of the PowerShellPlus. In a script file, click Snippet/Insert on the toolbar or select Insert Snippet in the context menu in the main Editor window. You will be able to select a snippet. You can create you own snippets with the PowerShellPlus (via Snippets/ New on the toolbar).
|Dr. Holger Schwichtenberg is one of Germany's well-known experts for .NET and Windows Scripting technologies, is a Microsoft MVP, a .NET Code Wise Member, a board member of codezone.de, MSDN Online Expert, and a INETA speaker. He has published more than 20 books for Addison Wesley and Microsoft Press in Germany, in addition to more than 400 journal articles, notably for the IT journals iX, DOTNET Pro, and Windows IT Pro. He can be reached at email@example.com.|
This was first published in September 2008