Many of the designations used by manufacturers and sellers to distinguish their products areclaimed as trademarks. Where those designations appear in this book, and the publisher wasaware of a trademark claim, the designations have been printed with initial capital letters or in allcapitals.
The author and publisher have taken care in the preparation of this book, but make no expressedor implied warranty of any kind and assume no responsibility for errors or omissions. No liabilityis assumed for incidental or consequential damages in connection with or arising out of the use ofthe information or programs contained herein.
The publisher offers excellent discounts on this book when ordered in quantity for bulk purchasesor special sales, which may include electronic versions and/or custom covers and content partic-ular to your business, training goals, marketing focus, and branding interests. For more informa-tion, please contact:
U.S. Corporate and Government Sales(800) [email protected]
For sales outside the United States please contact:
International [email protected]
Visit us on the Web: www.informit.com/aw
Library of Congress Cataloging-in-Publication Data
Schwichtenberg, Holger.Essential PowerShell / Holger Schwichtenberg.
p. cm.ISBN 978-0-672-32966-1
1. Windows PowerShell (Computer programming language) 2. Command languages(Computer science) 3. Scripting languages (Computer science) 4. Systems programming(Computer science) 5. Microsoft Windows (Computer file) I. Title.
QA76.73.W56S39 2008005.4’2—dc22
2008020010
Copyright © 2008 by Pearson Education, Inc.
All rights reserved. Printed in the United States of America. This publication is protected by copy-right, and permission must be obtained from the publisher prior to any prohibited reproduction,storage in a retrieval system, or transmission in any form or by any means, electronic, mechani-cal, photocopying, recording, or likewise. For information regarding permissions, write to:
Pearson Education, IncRights and Contracts Department501 Boylston Street, Suite 900Boston, MA 02116Fax (617) 671 3447
ISBN-13: 978-0-672-32966-1ISBN-10: 0-672-2966-2
Text printed in the United States on recycled paper at RR Donnelley in Crawfordsville, Indiana.First printing June 2008
This Book Is Safari Enabled
The Safari® Enabled icon on the cover of your favorite technology book means the book is avail-able through Safari Bookshelf. When you buy this book, you get free access to the online editionfor 45 days.
Safari Bookshelf is an electronic reference library that lets you easily search thousands of techni-cal books, find code samples, download chapters, and access technical information whenever andwherever you need it.
To gain 45-day Safari Enabled access to this book:
■ Go to http://www.informit.com/onlineedition■ Complete the brief registration form■ Enter the coupon code LJRM-BWZP-1HUA-KCPF-YA2S
If you have difficulty registering on Safari Bookshelf or accessing the online edition, please [email protected].
Editor-in-ChiefKaren Gettman
Executive EditorNeil Rowe
DevelopmentEditorMark Renfrow
Managing EditorKristy Hart
Project EditorBetsy Harris
Copy EditorKeith Cline
IndexerPublishing Works,Inc.
ProofreaderPaula Lowell
Technical EditorTony Bradley
PublishingCoordinatorCindy Teeters
Cover DesignerGary Adair
CompositorNonie Ratcliff
PREFACE
Windows PowerShell is one of the most amazing products Microsoft hasreleased in recent years, because it brings console-based system adminis-tration and scripting to the next level of abstraction. PowerShell is an excel-lent replacement for classic Windows shell commands and for WindowsScript Host (WSH). PowerShell copies a lot of good features from UNIXshells and combines them with the power of the .NET Framework. Incontrast to WSH, PowerShell enables consistent, straightforward,command-line system administration that does not require much softwaredevelopment knowledge.
Unfortunately, in the first version of PowerShell, the number of high-level commands is limited. For many tasks, lower-level concepts arerequired, especially the .NET Framework and Windows ManagementInstrumentation (WMI).
What Does This Book Cover?
This book covers the standard PowerShell commandlets, additional freecommandlets (for example, PowerShell Community Extensions), and thedirect use of classes from the .NET Framework, the Component ObjectModel (COM), WMI, and the Active Directory Service Interface (ADSI).
Because PowerShell is an extensive topic, this book cannot provide anexhaustive reference of all PowerShell commands and solutions for all pos-sible administrative tasks. However, you will find a concise introduction tothe most common command and scenarios. For more detailed informationabout PowerShell, refer to the Microsoft documentation for PowerShell,WMI, ADSI, and the .NET Framework (approximately 100,000 pages) asan additional source.
xv
Who Should Read This Book?
The primary target audience comprises Windows administrators seeking amethod of automated system administration that is more powerful than theclassic Windows Shell but less complex than WSH and the associatedCOM components. After reading this book, administrators will be able touse PowerShell as their day-to-day command-line interface for all admin-istrative tasks.
As a prerequisite, aside a good knowledge of the Windows operationsystem, you should have a basic understanding of object-oriented pro-gramming languages. Basic concepts of object orientation such as classes,objects, attributes, and methods are not explained in this book.
How This Book Is Structured
This book is organized into 24 chapters, some of which, based on your pre-vious experience and knowledge of certain concepts, you might find easierto understand than others. The 24 chapters are split into two parts:
■ Part I: Getting Started with PowerShell. Part I introduces thePowerShell architecture, all basic concepts (such as pipelining andnavigation), the PowerShell Script Language, and the tools youshould know.
■ Part II: Windows PowerShell in Action. Part II coversPowerShell script solutions for day-to-day administrative tasksrelated to Windows services and Windows application, such as filesystem, processes, event logs, registry, networking, printers, docu-ments, databases, Active Directory, and software installation. Eachchapter contains dozens of self-contained examples.
The appendixes contain a list of all commandlets from PowerShell 1.0,the PowerShell Community Extensions 1.1.1, and the www.IT-Visions.dePowerShell Extensions 2.0. You will also find a short preview of the nextversion of Windows PowerShell (Version 2.0).
Throughout the text, you will find codes that match up to codes inAppendix C, “Bibliography.” These codes are encased in brackets (forexample, [MS01]). The appendix lists the code, the correlating subject, and
xvi Preface
a link that will provide you with more information.Occasionally, when a line of code is too long to fit on one line in the
printed text, a code-continuation character has been used to show that theline continues. For example
"{0} can be reached at {1}.
➥This information is dated: {2:D}." -f $a, $b, $c
This Book’s Website
Many of the scripts are available for download from its website,www.Windows-Scripting.com. This website also contains errata for thisbook and the option to offer feedback to the author.
Preface xvii
3
C H A P T E R 1
FIRST STEPS WITH WINDOWSPOWERSHELL
In this chapter:What Is Windows PowerShell? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3Downloading and Installing PowerShell Community Extensions . . . . . . . . 16Testing the PowerShell Extensions . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18Downloading and Installing the PowerShellPlus . . . . . . . . . . . . . . . . . . 19Testing the PowerShell Editor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
This chapter introduces Windows PowerShell and helps you set up yourenvironment. In addition, the chapter provides a few easy examples thatdemonstrate how to use PowerShell.
What Is Windows PowerShell?
Windows PowerShell (WPS) is a new .NET-based environment forconsole-based system administration and scripting on Windows platforms.It includes the following key features:
■ A set of commands called commandlets■ Access to all system and application objects provided by Component
Object Model (COM) libraries, the .NET Framework, andWindows Management Instrumentation (WMI)
■ Robust interaction between commandlets through pipelining basedon typed objects
■ A common navigation paradigm for different hierarchical or flatinformation stores (for example, file system, registry, certificates,Active Directory, and environment variables)
■ An easy-to-learn, but powerful scripting language with weak andstrong variable typing
■ A security model that prevents the execution of unwanted scripts■ Tracing and debugging capabilities■ The ability to host WPS in any application
This book includes syntax and examples for these features, except thelast one, which is an advanced topic that requires in-depth knowledge of a.NET language such as C#, C++/CLI, or Visual Basic .NET.
A Little Bit of HistoryThe DOS-like command-line window survived many Windows versions inalmost unchanged form. With WPS, Microsoft now provides a successorthat does not just compete with UNIX shells, it surpasses them in robust-ness and elegance. WPS could be called an adaptation of the concept ofUNIX shells on Windows using the .NET Framework, with connectionsto WMI.
Active Scripting with Windows Script Host (WSH, pronounced“wish”) is much too complex for many administrators because it presup-poses much knowledge about object-oriented programming and COM.The many exceptions and inconsistencies in COM make WSH and theassociated component libraries hard to learn.
Even during the development of Windows Server 2003, Microsoftadmitted that it had asked UNIX administrators how they administer theiroperating system. The short-term result was a large number of additionalcommand-line tools included in Windows Server 2003. However, the long-term goal was to replace the DOS-like command-line window of Windowswith a new, much more powerful shell.
Upon the release of the Microsoft .NET Framework in 2002, manypeople were expecting a “WSH.NET.” However, Microsoft stopped thedevelopment of a new WSH for the .NET Framework because it foresawthat using .NET-based programming languages such as C# and VisualBasic .NET would require administrators to know even more about object-oriented software development.
4 Chapter 1 First Steps with Windows PowerShell
Microsoft recognized the popularity of and satisfaction with UNIXshells and decided to merge the pipelining concept of UNIX shells withthe .NET Framework. The goal was to develop a new shell that was sim-ple to use but nearly as robust as a .NET program. The result: WPS.
In the first beta version, the new shell was presented under the codename Monad at the Professional Developer Conference (PDC) in October2003 in Los Angeles. After the intermediate names Microsoft Shell (MSH)and Microsoft Command Shell, the shell received its final name,PowerShell, in May 2006. The final version of WPS 1.0 was released onNovember 11, 2006 at TechEd Europe 2006.
NOTE The main architect of WPS 1.0 was Jeffrey Snover. He is always willingto discuss his “baby” and answer questions. At large international Microsofttechnical conferences, such as the Professional Developer Conference (PDC) andTechEd, you can easily find him; he is the only person at the Microsoft boothswearing a tie.
Why Use WPS?If you need a reason to use WPS, here it comes. Just consider the follow-ing solution for one common administrative task in both the old WSH andthe new WPS.
An inventory script for software is to be provided that will read theinstalled MSI packages using WMI. The script will get the informationfrom several computers and summarize the results in a CSV file(softwareinventory.csv). The names (or IP addresses) of the computers tobe queried are read from a TXT file (computers.txt).
The solution with WSH (Listing 1.1) requires 90 lines of code (includ-ing comments and parameterizing). In WPS, you can do the same thing injust 13 lines (Listing 1.2). If you do not want to include comments andparameterizing, you need just one line (Listing 1.3).
Listing 1.1 Software Inventory Solution 1: WSH
Option Explicit
' --- Settings
Const InputFileName = "computers.txt"
Const OutputFileName = "softwareinventory.csv"
What Is Windows PowerShell? 5
1.FIRST
STEPSW
ITHW
INDO
WS
PO
WERSHELL
(continues)
Listing 1.1 Software Inventory Solution 1: WSH (continued)
Const Query = "SELECT * FROM Win32_Product where not
➥Vendor like '%Microsoft%’"
Dim objFSO ' Filesystem Object
Dim objTX ' Textfile object
Dim i ' Counter
Dim Computer ' Current Computer Name
Dim InputFilePath ' Path for InputFile
Dim OutputFilePath ' Path of OutputFile
' --- Create objects
Set objFSO = CreateObject("Scripting.FileSystemObject")
' --- Get paths
InputFilePath = GetCurrentPath & "\" & InputFileName
OutputFilePath = GetCurrentPath & "\" & OutputFileName
' --- Create headlines
Print "Computer" & ";" & _
"Name" & ";" & _
"Description" & ";" & _
"Identifying Number" & ";" & _
"Install Date" & ";" & _
"Install Directory" & ";" & _
"State" & ";" & _
"SKU Number" & ";" & _
"Vendor" & ";" & _
"Version"
' --- Read computer list
Set objTX = objFSO.OpenTextFile(InputFilePath)
' --- Loop over all computers
Do While Not objTX.AtEndOfStream
Computer = objTX.ReadLine
i = i + 1
WScript.Echo "=== Computer #" & i & ": " & Computer
GetInventory Computer
Loop
' --- Close Input File
6 Chapter 1 First Steps with Windows PowerShell
objTX.Close
' === Get Software inventory for one computer
Sub GetInventory(Computer)
Dim objProducts
Dim objProduct
Dim objWMIService
' --- Access WMI
Set objWMIService = GetObject("winmgmts:" &_
"{impersonationLevel=impersonate}!\\" & Computer &_
"\root\cimv2")
' --- Execeute WQL query
Set objProducts = objWMIService.ExecQuery(Query)
' --- Loop
For Each objProduct In objProducts
Print _
Computer & ";" & _
objProduct.Name & ";" & _
objProduct.Description & ";" & _
objProduct.IdentifyingNumber & ";" & _
objProduct.InstallDate & ";" & _
objProduct.InstallLocation & ";" & _
objProduct.InstallState & ";" & _
objProduct.SKUNumber & ";" & _
objProduct.Vendor & ";" & _
objProduct.Version
Next
End Sub
Sub Print(s)
Dim objTextFile
Set objTextFile = objFSO.OpenTextFile(OutputFilePath, 8, True)
objTextFile.WriteLine s
objTextFile.Close
End Sub
' === Get Path to this script
Function GetCurrentPath
GetCurrentPath = objFSO.GetFile (WScript.ScriptFullName).ParentFolder
End Function
What Is Windows PowerShell? 7
1.FIRST
STEPSW
ITHW
INDO
WS
PO
WERSHELL
Listing 1.2 Software Inventory Solution 2: WPS Script
# Settings
$InputFileName = "computers.txt"
$OutputFileName = "softwareinventory.csv"
$Query = "SELECT * FROM Win32_Product where not
➥Vendor like '%Microsoft%’"
# Read computer list
$Computers = Get-Content $InputFileName
# Loop over all computers and read WMI information
$Software = $Computers | foreach { get-wmiobject -query $Query -
computername $_ }
# Export to CSV
$Software | select Name, Description, IdentifyingNumber, InstallDate,
➥InstallLocation, InstallState, SKUNumber, Vendor, Version |
➥export-csv $OutputFileName -notypeinformation
Listing 1.3 Software Inventory Solution 3: WPS Pipeline Command
Get-Content "computers.txt" | Foreach {Get-WmiObject -computername
➥$_ -query "SELECT * FROM Win32_Product where not
➥Vendor like '%Microsoft%’" } | Export-Csv "Softwareinventory.csv"
➥–notypeinformation
Downloading and Installing WPSWindows Server 2008 is the first operating system that includes WPS onthe DVD. However, it is an additional feature that can be installed throughAdd Feature in the Windows Server 2008 Server Manager.
WPS can be downloaded (see Figure 1.1) and installed as an add-on tothe following operating systems:
■ Windows XP for x86 with Service Pack 2■ Windows XP for x64 with Service Pack 2■ Windows Server 2003 for x86 with Service Pack 1
8 Chapter 1 First Steps with Windows PowerShell
■ Windows Server 2003 for x64 with Service Pack 1■ Windows Server 2003 for Itanium with Service Pack 1■ Windows Vista for x86 ■ Windows Vista for x64
Note that WPS is not included in Windows Vista, although Vista undWPS were released on the same day. Microsoft decided not to ship any.NET-based applications with Vista. Only the .NET Framework itself ispart of Vista.
POWERSHELL DOWNLOAD PAGE www.microsoft.com/windowsserver2003/technologies/management/powershell/download.mspx
What Is Windows PowerShell? 9
1.FIRST
STEPSW
ITHW
INDO
WS
PO
WERSHELL
Figure 1.1 WPS download website
WPS requires that .NET Framework 2.0 or later be installed beforerunning WPS setup. Because Vista ships with .NET Framework 3.0 (whichis a true superset of 2.0), no .NET installation is required for it. However,on Windows XP and Windows Server, you must install .NET Framework2.0, 3.0, or 3.5 first (if they are not already installed by another application).
MICROSOFT .NET FRAMEWORK 3.0 REDISTRIBUTABLE PACKAGEwww.microsoft.com/downloads/details.aspx?FamilyId=10CC340B-F857-4A14-83F5-25634C3BF043&displaylang=en
The setup routine installs WPS to the directory %systemroot%\system32\WindowsPowerShell\V1.0 (on 32-bit systems) or %systemroot%\Syswow64\WindowsPowerShell\V1.0 (for 64-bit systems). You cannotchange this folder during setup.
TIP If for any reason you want to uninstall WPS, note that WPS is considered asoftware update to the Windows operating system (that is, not a normal applica-tion). Therefore, in the Add or Remove Programs control panel applet, it is notlisted as a program; instead, it is listed as an update called Hotfix for Windows(KB x). The Knowledge Base (KB) number varies on different operating systems.However, you can identify WPS installation in the list by its icon (see Figure1.2). On Windows XP and Windows Server 2003, you must check the ShowUpdates check box to see the WPS installation.
Taking WPS for a Test RunThis section includes some commands to enable you to try out a few WPSfeatures. WPS has two modes, interactive mode and script mode, whichare covered separately.
10 Chapter 1 First Steps with Windows PowerShell
What Is Windows PowerShell? 11
1.FIRST
STEPSW
ITHW
INDO
WS
PO
WERSHELL
Figure 1.2 The uninstall option for WPS is difficult to find. (This screenshot isfrom Windows Server 2003.)
WPS in Interactive ModeFirst, you’ll use WPS in interactive mode.
Start WPS. An empty WPS console window will display (see Figure1.3). At first glance, you might not see much difference between it and thetraditional Windows console. However, there is much more power in WPS,as you will soon see.
At the command prompt, type get-process and then press theReturn key. A list of all running processes on your local computer will dis-play (see Figure 1.4). This was your first use of a simple WPS commandlet.
NOTE Note that the letter case does not matter. WPS does not distinguishbetween uppercase and lowercase letters in commandlet names.
Figure 1.3 Empty WPS console window
12 Chapter 1 First Steps with Windows PowerShell
Figure 1.4 The Get-Process commandlet output
At the command prompt, type get-service i*. A list of all installedservices with a name that begins with the letter I on your computer will
display (see Figure 1.5). This was your first use of a commandlet withparameters.
What Is Windows PowerShell? 13
1.FIRST
STEPSW
ITHW
INDO
WS
PO
WERSHELL
Figure 1.5 A filtered list of Windows services
Type get- and then press the Tab key several times. You will see WPScycling through all commandlets that start with the verb get. Microsoftcalls this feature tab completion. Stop at Get-Eventlog. When you pressEnter, WPS prompts for a parameter called LogName (see Figure 1.6).LogName is a required parameter. After typing Application and press-ing Return, you will see a long list of the current entries in your Applicationevent log.
Figure 1.6 WPS prompts for a required parameter.
The last example in this section introduces you to the pipeline featuresof WPS. Again, we want to list entries from a Windows event log, but thistime we want to get only some entries. The task is to get the most recentten events that apply to printing. Enter the following command, whichconsists of three commandlets connected via pipes (see Figure 1.7):
Get-EventLog system | Where-Object { $_.source -eq "print" }
➥ | Select-Object -first 10
Note that WPS seems to get stuck for a few seconds after printing thefirst ten entries. This is the correct behavior because the first commandlet
(Get-EventLog) will receive all entries. The filtering is done by the sub-sequent commandlets (Where-Object and Select-Object). Unfortu-nately, Get-EventLog has no included filter mechanism.
14 Chapter 1 First Steps with Windows PowerShell
Figure 1.7 Filtering event log entries
WPS in Script ModeNow it’s time to try out PowerShell in script mode and incorporate a WPSscript. A WPS script is a text file that includes commandlets/elements ofPowerShell Script Language (PSL). The script in this example creates anew user account on your local computer.
Open Windows Notepad (or any other text editor) and enter the fol-lowing lines of script code (which consists of comments, variable declara-tions, COM library calls, and shell output):
Listing 1.4 Create a User Account
### PowerShell Script
### Create local User Acount
# Variables
$Name = "Dr. Holger Schwichtenberg"
$Accountname = "HolgerSchwichtenberg"
$Description = "Author of this book / Website: www.windows-scripting.com"
$Password = "secret+123"
$Computer = "localhost"
"Creating User on Computer $Computer"
# Access to Container using the COM library
➥"Active Directory Service Interface (ADSI)"
$Container = [ADSI] "WinNT://$Computer"
# Create User
$objUser = $Container.Create("user", $Accountname)
$objUser.Put("Fullname", $Name)
$objUser.Put("Description", $Description)
# Set Password
$objUser.SetPassword($Password)
# Save Changes
$objUser.SetInfo()
"User created: $Name"
Save the text file with the name createuser.ps1 into the directoryc:\temp. Note that the file extension must be .ps1.
Now start WPS. Try to start the script by typing c:\temp\createuser.ps1. (You can use tab completion for the directory and file-names.) This attempt will fail because script execution is, by default, notallowed in WPS (see Figure 1.8). This is not a bug; it is a security feature.(Remember the Love Letter worm for WSH?)
What Is Windows PowerShell? 15
1.FIRST
STEPSW
ITHW
INDO
WS
PO
WERSHELL
Figure 1.8 Script execution is prohibited by default.
For our first test, we will weaken the security a little bit (just a little).We will allow scripts that reside on your local system to run. However,scripts that come from network resources (including the Internet) willneed a digital signature from a trusted script author. Later in this book youlearn how to digitally sign WPS scripts. You also learn to restrict your sys-tem to scripts that you or your colleagues have signed.
To allow the script to run, enter the following:
Set-ExecutionPolicy remotesigned
Then, start the script again (see Figure 1.9). Now you should see amessage that the user account has been created (see Figure 1.10).
16 Chapter 1 First Steps with Windows PowerShell
Figure 1.9 Running your first script to create a user account
Figure 1.10 The newly created user account
Downloading and Installing PowerShell CommunityExtensions
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 withthe verbs get and set. And the number of those commandlets is quitesmall compared to the large number of objects that Windows operatingsystems provide. All the other commandlets are, more or less, related toWPS 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 commandletssuch 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 tocontribute. New versions are published on a regular basis. At the time ofthis writing, version 1.1.1 is the current stable release.
DOWNLOAD POWERSHELL COMMUNITY EXTENSIONSwww.codeplex.com/PowerShellCX
PSCX is provided as a setup routine that should be installed after WPShas been installed successfully.
Downloading and Installing PowerShell Community Extensions 17
1.FIRST
STEPSW
ITHW
INDO
WS
PO
WERSHELL
Figure 1.11 PowerShell Community Extension website
You can incorporate additional functionality of PSCX into WPS byusing a profile script (see Figure 1.12). Just copy this profile script to yourMy Documents/Windows PowerShell directory, if you want, during PSCXsetup. As a beginner, you should use this option.
18 Chapter 1 First Steps with Windows PowerShell
Figure 1.12 The PSCX profile script that was created during PSCX setup
Testing the PowerShell Extensions
The installation of PSCX changes the WPS console just a bit. Instead of thecurrent path, the prompt now contains a counter. However, the path doesdisplay in the window’s title.
Start WPS and type Get-DomainController (if your computer is amember of an Active Directory) or test PSCX by using Ping-Host withany computer on your network (see Figure 1.13).
Figure 1.13 Testing Get-DomainController and Ping-Host
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 wasfree even for commercial use. However, PowerShell IDE never made it toa final release and was discontinued.
The PowerShellPlus Editor is part of PowerShellPlus. PowerShellPlusconsists of the editor and a console that provides IntelliSense while usingthe PowerShell interactively.
POWERSHELLPLUS WEBSITE www.powershell.com
PowerShellPlus does not need any setup. It is a true .NET applicationwith XCopy deployment. You just unpack the ZIP file to the directory ofyour choice and start the PowerShellPlus.exe that is part of thepackage.
Downloading and Installing the PowerShellPlus 19
1.FIRST
STEPSW
ITHW
INDO
WS
PO
WERSHELL
Testing the PowerShell Editor
The PowerShellPlus has, according to the WPS console, two modes: aninteractive mode and a script mode (see Figure 1.14). After starting thePowerShellPlus, you will see the interactive mode. You can use any com-mandlet (or pipeline). When you press Return, the commandlet is exe-cuted, and the result displays in the same window. The handy feature is theIntelliSense. If you enter Get-P, you will see a drop-down list of the avail-able commandlets that start with these letters.
20 Chapter 1 First Steps with Windows PowerShell
Figure 1.14 WPS IDE in interactive mode
To use the PowerShellPlus in script mode, click Code Editor and cre-ate a new script file (New/PowerShell Script) or open an existing script PS1file (Open). Now open the script file CreateUser.ps1 that you createdearlier. You will see line numbers, and you will encounter the sameIntelliSense 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 dis-play in the interactive Windows in the background.
WARNING Make sure the user account does not exist before running thescript. Otherwise the script will fail with the error “The account already exists.”
Testing the PowerShell Editor 21
1.FIRST
STEPSW
ITHW
INDO
WS
PO
WERSHELL
Figure 1.15 WPS IDE in script mode
Another great feature is debugging. Place the cursor on any line inyour 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 thescript. You will see the PowerShellPlus Editor executing the script in slowmotion, marking the current line yellow and stopping at the line with thebreakpoint (see Figure 1.16). In the Variables Inspector window, you caninspect the current value of all variables. In the interactive window, youcan type any WPS command that will be executed within the current con-text. That is, you can interactively access all script variables. To continuethe script, press F8 or click the Continue icon in the toolbar.
Figure 1.16 Script debugging with the WPS IDE
Code snippets are also a nice feature of the PowerShellPlus. In a scriptfile, click Snippet/Insert on the toolbar or select Insert Snippet in the con-text 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).
Summary
Windows PowerShell is a new .NET-based environment for scripting andis an interactive command-line shell. WPS is an optional feature onWindows Server 2008 and an add-on for Windows XP, Vista, and Server2008. Commands in WPS are called commandlets. The PSCX extendsWPS with additional commandlets.
22 Chapter 1 First Steps with Windows PowerShell
The PowerShellPlus is an alternative shell for WPS commands and aneditor for WPS scripts.
In the next chapter, you learn much more about commandlets andpipelines. You also learn how to get help if you are seeking a command orthe available options for a commandlet.
Summary 23
1.FIRST
STEPSW
ITHW
INDO
WS
PO
WERSHELL
INDEX
453
Symbols& (ampersand) operator,
109@ (at symbol) in hash
tables, 107= (equals sign), 109( ) (parentheses) in
methods, 64+ (plus sign operator),
54, 108“” (quotation marks) in
parameters, 26; (semicolons) in
commands, 90* (star operator), 108, 356| (vertical line) for
pipelines, 43
Aaccess control entries.
See ACEsaccess control lists.
See ACLsaccess rights, 403-406accessing
databasescommands, 383-385connections, 380-382data readers, 386-388DataSets. See
DataSets
provider-independent,382-383
www.IT-Visions.deextensions, 396-399
directory services, 313file shares, 221hash tables, 107WMI
collections, 146members, 142-144objects, 137-138
ACEs (access controlentries), 225, 402
adding to ACLs, 418-419contents, 402deleting from ACLs,
421-423reading, 410-411
ACLs (access control lists),225, 401-402
ACEsadding, 418-419contents, 402deleting, 421-423reading, 410-411
classes, 406control holders, 408inheritance
hierarchy, 406ObjectSecurity, 406reading ACLs, 408-409resources, 407
commandlets, 401configuring, 425-426reading, 408-409transferring, 424
Active Directoryextensions
PSCX, 361Quest, 365www.IT-Visions.de,
362-364group members
assignments, 345creating/filling, 345deleting, 346listing, 343-344
organizational units, 346-347
schemadocumentation, 338website, 450
searching, 314indexed attributes, 354multivalued attributes,
355-356result restrictions, 357star operator, 356
structure, 365-367user accounts
authentication, 341creating, 339-340deleting, 342moving, 343
passwords, 340renaming, 342
user class, attributes,335-338
Active Directory ServiceInterfaces. See ADSI
Active DirectoryManagement Objects(ADMO), 365
AD Access Change/Breakin RC2 website, 449
ADAM (Active DirectoryApplicationMode), 365
add-content commandlet,429
binary files, 238text files, writing, 236
add-directoryentrycommandlet,362, 429
add-history commandlet,429
add-member commandlet,429
Add-PSSnapincommandlet,175-176, 429
add-user commandlet,362, 429
addingACEs to ACLs, 418-419snap-ins, 175users to groups, 345virtual web servers,
308-311AddPrinterConnection( )
method(Win32_Printerclass), 287
ADMO (Active DirectoryManagementObjects), 365
454 Index
ADO.NET, 373architecture, 374data providers, 375data source control
elements, 377DataReader object,
376-378DataSet object, 376-378SQL Servers, listing
available, 376ADSI (Active Directory
Service Interfaces),314
architecture, 316deficiencies, 321-323directory services,
compared, 320DirectoryEntry class,
318-319integration, 316object model, 318property cache, 329search queries, 319
aliases, 29creating, 30-31enumerating, 29properties, 68
ambiguous commandlets,180
ampersand (&) operator,109
Analyzer, 164analyzing pipeline
content, 59alias properties, 68code properties, 68ETS, 69-70get-member command-
let, 62, 66-69get-pipelineinfo
commandlet, 60methods, 64
note properties, 67properties, 65property sets, 66script properties, 67
AppendChild( ) method, 246
AppendData right, 403architecture
Active Directory, 365-367
ADO.NET, 374ADSI, 316
arrays, 105-106associative, 106-108declaring, 105defining, 105joining, 105listing, 105multidimensional, 106
at symbol (@) in hashtables, 107
attributes, 213directory entries
reading, 328writing, 329
FileSystemAccessRuleobjects, 410
indexed, 354mailboxes, 304multivalued, 355-356Property, 318services, 278user class (Active
Directory), 335-338authentication, 58, 341autostart applications, 263
B–Cbinary files, 238BIOS settings, 282boot configuration
settings, 282
calculated parameters, 27-28
calculations (pipelines), 76calling methods, 64castrating objects, 73-74Change( ) method
(Win32_Serviceclass), 278
ChangePermissionright, 403
checking XML files, 242-243
classesattributes, 213CmdletInfo, 179COM
COM objects, 135creating instances, 133existing instances, 134
DateTime, 102DbProviderFactories, 382DirectoryEntries, 319DirectoryEntry, 318-319DriveInfo, 208FileInfo, 214group policies, 367Hashtable, 107IIsApplicationPool, 305IIsComputer, 305IIsWebServer, 305IIsWebService, 305IIsWebVirtualDir, 305MailMessage, 302ManagementDateTime-
Converter, 145.NET, 129
assemblies, loading, 131constructor
parameters, 130enumerations, 132help, 38-40instances, creating, 130
Index 455
object analysis, 132static members, 130
ObjectSecurity, 406security, 406
control holders, 408inheritance
hierarchy, 406ObjectSecurity, 406reading ACLs, 408-409resources, 407
SmtpClient, 302String, 99TimeSpan, 103user (Active Directory),
335-338WebClient, 300Win32_Computersystem,
281Win32_Desktop, 315Win32_LogicalDisk,
207-210Win32_NetworkAdapter
Configuration, 296Win32_NTLogEvent, 291Win32_Operating
System, 281Win32_PerfRawData, 292Win32_Product, 259Win32_Service, 277Win32_Share, 221Win32_StartupCommand,
263Win32_Trustee, 226WMI, 135
available, listing, 148collections,
accessing, 146instances, creating, 149object access, 137-138object adapter, 139object analysis, 140object filtering/
selecting, 146-147
properties/methods,142-144
queries, 147static class
members, 144System.Management
object model, 135type indicators, 139WPS support, 136
XMLDocument,229, 244
clear-content commandlet,429
clear-item commandlet,206, 429
clear-itemproperty commandlet, 429
clear-variable commandlet,429
clipboard, 200close-dbconnection
commandlet, 430cmdlet development
guidelineswebsite, 450
Cmdlet help website, 450CmdletInfo class, 179code properties, 68COM classes
COM objects, 135instances
creating, 133existing, 134
command mode, 33, 154command-processing
modes, 33commandlets
add-content, 429binary files, 238text files, writing, 236
add-directoryentry, 362, 429
add-history, 429add-member, 429add-pssnapin, 175, 429add-user, 362, 429ambiguous, 180case sensitivity, 29clear-content, 429clear-item, 206, 429clear-itemproperty, 429clear-variable, 429close-dbconnection, 430compare-object, 78, 430convert-html, 251convert-path, 430convert-xml, 249, 430convertfrom-base64, 430convertfrom-secure-
string, 430convertto-base64, 430convertto-html, 430convertto-macos9line-
ending, 430convertto-securestring,
430convertto-unixline-
ending, 430convertto-windowsline-
ending, 430copy-item, 212, 254, 430copy-itemproperty, 430data access, 396debugging parameters,
171definition, 25disable-mailbox, 304disconnect-terminal-
session, 430Exchange Server 2007,
184-185export-alias, 431export-bitmap, 431export-clixml, 248, 431export-console, 431
456 Index
export-csv, 239, 431expression integration, 33extensions, 174-175, 181external, 33-34file system administra-
tion, 205-206foreach-object, 105,
235, 431format-byte, 431format-custom, 431format-hex, 431format-list, 431format-table, 431format-wide, 431format-xml, 244, 431get-, 35get-acl, 401, 431get-adobject, 314,
358, 431get-alias, 30, 432get-authenticode-
signature, 432get-bios, 432get-cdromdrive, 432get-childitem, 432
directory content, 210Filter parameter, 211include parameter, 211registry keys, 253
get-clipboard, 200, 432get-command, 432get-computerinfo, 432get-computername, 432get-content, 206, 432
binary files, 238files, reading, 229, 235
get-credential, 58, 432get-culture, 188, 432get-currentuser, 432get-datarow, 396get-datatable, 396get-date, 102, 432get-dbconnection, 432
get-dbrow, 433get-dbtable, 433get-dhcpserver, 433get-directory, 362get-directorychildren, 433get-directoryentry,
362, 433get-directoryvalue,
362, 433get-disk, 206, 433get-domaincontroller,
324, 433get-eventlog, 290, 433get-executionpolicy, 433get-exportedtype, 433get-fileversioninfo, 433get-foregroundwindow,
434get-hash, 434get-help, 35, 434get-history, 186, 434get-host, 187, 434get-item, 434
file properties, 213registry keys, 254
get-itemproperty, 255, 434
get-ITVisions, 434get-keyboard, 434get-location, 206, 434get-mailbox, 303get-mailboxdatabase, 303get-member, 62,
66-68, 434alias properties, 68code properties, 68methods, 64note properties, 67output, reducing, 69properties, 65property sets, 66script properties, 67
get-memorydevice, 434
get-metadata, 435get-mountpoint, 435get-networkadapter, 435get-PEheader, 435get-pfxcertificate, 435get-pipelineinfo, 60, 435get-pointingdevice, 435get-privilege, 435get-process, 11, 435
processes, enumerat-ing, 267-268
processes, filtering, 268get-process | out file, 55get-process | out-printer,
55get-processor, 435get-psdrive, 83, 206, 435get-psprovider, 84, 435get-pssnapin, 435get-pssnapinhelp, 435get-random, 435get-reparsepoint, 435get-service, 272, 435get-service i, 13get-shortpath, 436get-sounddevice, 436get-storagegroup, 303get-tabexpansion, 436get-tapedrive, 436get-terminalsession, 436get-tracesource, 173, 436get-uiculture, 188, 436get-unique, 436get-usbcontroller, 436get-variable, 436get-videocontroller, 436get-wmiobject, 135,
144, 436hardware information,
284list parameter, 148
group-object, 74, 436help, 35, 38
Index 457
import-alias, 436import-bitmap, 436import-clixml, 436import-csv, 240, 436import-dbcommand, 437invoke-dbcommand, 396invoke-expression,
109, 437invoke-history, 437invoke-item, 437invoke-scalardb-
command, 437join-path, 437join-string, 102, 437listing of, 35measure-command,
173, 437measure-object, 76, 437move-item, 206,
212, 437move-itemproperty, 437navigation, 84new-alias, 30, 437new-hardlink, 218, 437new-item, 206, 437
registry keys, 254text files, creating, 236
new-itemproperty, 256, 437
new-junction, 218, 437new-mailboxdatabase,
303new-object, 437new-psdrive, 438new-service, 278, 438new-shortcut, 217, 438new-storagegroup, 303new-symlink, 220, 438new-timespan, 103, 438new-variable, 438nouns, 29out-clipboard, 438out-default, 51, 438
out-file, 55, 236, 438out-host, 51, 438out-null, 438out-printer, 55, 287, 438out-string, 438output, 49
printing, 55single values, 53-54standard, 51-53suppressing, 55text files, 55
parameters, 26-27calculated, 27-28case sensitivity, 29filtering output, 28placeholders, 29quotation marks, 26sequence, 27
ping-host, 296, 438pipelines
calculations, 76castrating objects,
73-74classic commands, 46comparing objects, 78content, analyzing. See
pipelines, contentanalyzing
creating, 43filtering objects, 70-72grouping objects,
74-75intermediate steps,
viewing, 76objects, 44-46output, 49-55Pipeline Processor,
47-49ramifications, 78sorting objects, 74user input, 56-58
placeholders, 29pop-location, 438
PSCX, 181-182, 214push-location, 438Quest, 183-184read-host, 56, 438remove-directoryentry,
362, 438remove-item, 206, 212,
254, 438remove-itemproperty,
257, 438remove-mountpoint, 439remove-psdrive, 439remove-pssnapin, 439remove-reparsepoint,
439remove-variable, 439rename-item, 206,
212, 439rename-itemproperty,
439resize-bitmap, 439resolve-assembly,
215, 439resolve-host, 299, 439resolve-path, 439restart-service, 277, 439resume-service, 439SCVMM, 185select-object, 70, 73, 439select-string, 237, 439select-xml, 244-246, 439send-smtpmail, 302, 439set-acl, 401, 440set-alias, 30, 440set-authenticodesigna-
ture, 120, 440set-clipboard, 200, 440set-content, 206, 440
binary files, 238text files, writing, 236
set-datarow, 396set-datatable, 396
458 Index
set-date, 104, 440set-dbtable, 440set-directoryvalue,
362, 440set-distributiongroup,
304set-executionpolicy,
119, 440set-filetime, 214, 440set-foregroundwindow,
440set-item, 206, 440set-itemproperty,
214, 440set-location, 206,
254, 441set-privilege, 441set-psdebug, 173, 441set-service, 278, 441set-tracesource, 173, 441set-variable, 441set-volumelabel,
210, 441snap-ins, 179sort-object, 74, 441split-path, 441split-string, 101, 441start-process,
269-270, 441start-service, 277, 441start-sleep, 122, 441start-tabexpansion, 441start-transcript, 441stop-process, 270, 441stop-service, 277, 441stop-terminalsession,
441stop-transcript, 441suspend-service, 442syntax, 26test-assembly, 442test-dbconnection,
396, 442
test-path, 442test-xml, 243, 442trace-command, 442tree-object, 78, 442update-formatdata, 442update-typedata, 442verbose parameter, 172where-object, 70, 442write-bzip2, 442write-clipboard, 200, 442write-debug, 442write-error, 53, 442write-gzip, 442write-host, 53, 442write-output, 443write-progress, 443write-tar, 443write-verbose, 443write-warn, 53write-warning, 443write-zip, 220, 443
commandsdatabase access, 383-385history, 186-187separating, 90
comments, 90CommitChanges( )
method, 329compare-object
commandlet, 78, 430comparing objects, 78complex pipelines, 48-49compression (files),
220-221computers
BIOS, 282boot configurations, 282event logs, 290
entries, 290-291names, 290remote access, 291
hardwareinformation, viewing,
284-285printers, 286-289
performance counters,292-293
pinging, 295product aviation
settings, 282recovery settings, 283serial numbers, 282settings, viewing,
281-283software versions, 282
configuringACLs, 425-426date and time, 104files
date and time, 214share permissions,
225-228networking, 296-298
confirm parameter, 171connections
databases, 380-382printers, 287
consolesinteractive mode, 11WPS, 151
command history, 186-187
command mode, 154functions, 152interpreter mode, 154PowerTab, 156snap-ins, loading,
175-176tab completion, 153Vista user account
control, 155
Index 459
constant values (variables), 95
constructors (.NET classes), 130
control structures, 110-112convert-html commandlet,
251convert-path commandlet,
430convert-xml commandlet,
249, 430convertfrom-base64
commandlet, 430convertfrom-securestring
commandlet, 430convertto-base64
commandlet, 430convertto-html
commandlet, 430convertto-macos9lineend-
ing commandlet, 430convertto-securestring
commandlet, 430convertto-unixlineending
commandlet, 430convertto-windowslineend-
ing commandlet, 430ConvertToDateTime( )
method, 145copy-item commandlet,
212, 254,430copy-itemproperty
commandlet, 430copying
files/folders, 212registry keys, 254
CreateDirectoriesright, 403
CreateElement( ) method, 246
CreateFiles right, 404
creatingCSV files, 239directory entries, 332Explorer links, 217file shares, 223-224,
229-232groups
Active Directory, 345policy links, 369-370
hardlinks, 218junction points, 218mailboxes, 303organizational units,
346-347public folders, 305registry keys, 254-257symbolic links, 220user accounts, 339-340websites from CSV files,
309-311CSV files, 239
creating, 239exporting, 239importing, 240websites, creating,
309-311customizing
file properties, 214service configuration,
278-279strings, 100XML documents, 246
Ddata
adapters, 391providers, 375readers, 386-388types, 92
listing of, 92registry, 257variables, 91-93
databasesaccess
commands, 383-385connections, 380-382data readers, 386-388DataSets. See
DataSetsprovider-independent,
382-383www.IT-Visions.de
extensions, 396-399ADO.NET, 373
architecture, 374data providers, 375data source control
elements, 377DataReader object,
376-378DataSet object,
376-378enumerating data
providers, 375SQL Servers, listing
available, 376example, 379mailboxes, 303
DataReader object, 376-378
DataSets, 389data adapter, 391object model,
376-378, 390provider-independent
example, 394-395provider-specific
example, 391-393XML exports/
imports, 395DataTable objects, 390date and time, 102-103, 145
files, 214periods of time, 103
460 Index
remote computers, 104setting, 104WMI date format con-
versions, 145DateTime class, 102DbProviderFactories
class, 382deactivating mailboxes, 304debug parameter, 171debugging
commandlet parametersfor, 171
PowerShellPlus, 21PowerShellPlus
Editor, 163step-by-step, 173verbose parameter, 172
declaringarrays, 105variables, 91
default naming context, 324
Delete right, 404DeleteSubdirectoriesAnd-
Files right, 404DeleteTree( ) method, 342deleting
ACEs to ACLs, 421-423directory entries, 332files/folders, 212group policy links,
370-372junction points, 219print jobs, 288registry keys, 254, 257text file content, 236users
Active Directory, 342groups, 346
virtual web servers, 311dependent services,
274-276
dialog boxesauthentication, 58user input, 57
digital signatures, 120-121directory content
files/folders operations,212-213
viewing, 210-212directory services
access, 313ADSI
compared, 320deficiencies, 321-323
paths, 323-325programming, 325
ADSI property cache, 329
binding meta objectsto directory entries,325-326
container objects, 331directory entries, 332directory entry
attributes, 328-329directory entry exis-
tence, checking, 327impersonation, 327object properties, 330
www.IT-Visions.de com-mandlets, 362-364
DirectoryEntries class, 319DirectoryEntry class,
318-319disable-mailbox
commandlet, 304disconnect-terminalsession
commandlet, 430DLL registration, 175DNs (distinguished
names), 323
documentsbinary files, 238CSV files, 239
creating, 239exporting, 239importing, 240
HTML, 251text files
content, deleting, 236reading, 235-236searching, 237writing to, 236-237
XML, 241checking, 242-243converting to XHTML
files, 249customizing, 246formatting, 244object pipeline, 248reading, 241searching with
XPath, 244domain controllers (Active
Directory), 366-367domains (Active
Directory), 366dot sourcing, 118downloading
PSCX, 17RSS feeds, 301WPS, 8
DownloadString( )method, 300
DriveInfo class, 208drives
defining, 87-88, 255free space, viewing,
208-210listing all, 206-207names, 210network, 210providers, 83-84
Index 461
Ee-mail, sending, 302ending processes, 270enumerating
aliases, 29data providers, 375file shares, 223group policies, 367-369.NET classes, 132processes, 267-268services, 272-273
environment variables,viewing, 283
equals sign (=), 109ErrorAction parameter,
125-127errors (scripts), 122
creating, 128handling, 125-127history, 128standard reactions, 127trap blocks, 128trapping example,
123-125ETS (Extended Type
System), 44pipeline content,
analyzing, 69-70website, 450
event logs, 290entries, 290-291filtering, 14names, 290remote access, 291
Exchange ManagementShell website, 451
Exchange Server 2007, 302basic operations, 302databases, listing, 303functionality, testing, 303mailboxes, 303-304
management shell, 184-185
public folder management, 305
scripts website, 451storage groups, 303
executable filesPE header information,
215PSCX commandlets, 214viewing, 215
ExecuteFile right, 404execution policies, 119execution time,
measuring, 173Exists( ) method, 327Explorer links, 216-217export-alias commandlet,
431export-bitmap
commandlet, 431export-clixml commandlet,
248, 431export-console
commandlet, 431export-csv commandlet,
239, 431exporting
CSV files, 239DataSets, 395
expressions, 32-33Extended Reflection, 44Extended Type System.
See ETSextensions
commandlets,174-175, 181
PSCXActive Directory, 361commandlets, 181-182LDAP filters, 358
Quest, 365www.IT-Visions.de, 183
Active Directory, 362-364
database access, 396-399
external commandlets, 33-34
Ffile system administration
access rights, 403-406commandlets, 205-206directory content,
viewing, 210-212drives
free space, displaying,208-210
listing all, 206-207names, 210network, 210
executable filesPE header
information, 215PSCX commandlets,
214viewing, 215
file compression, 220-221
file propertiescustomizing, 214date/time information,
214viewing, 213
file sharesaccessing, 221creating, 223-224enumerating, 223mass creation, 229-232permissions, 225-228
files/folders operations,212-213
462 Index
links, 216Explorer, 216-217hardlinks, 217-218junction points,
218-219symbolic, 220
FileInfo class, 214files
binary, 238compression, 220-221copying, 212CSV, 239
creating, 239exporting, 239importing, 240websites, creating,
309-311deleting, 212executable
PE header information, 215
PSCX commandlets,214
viewing, 215HTML, 251moving, 212names, 34properties
customizing, 214date/time information,
214viewing, 213
renaming, 212retrieving from HTTP
servers, 300-301shares
accessing, 221creating, 223-224enumerating, 223mass creation, 229-232permissions, 225-228
textcontent, deleting, 236reading, 235-236searching, 237writing to, 236-237
XML, 241checking, 242-243converting to XHTML
files, 249customizing, 246DataSet
exports/imports, 395formatting, 244object pipeline, 248reading, 241searching with
XPath, 244FileSystemAccessRule
objects, 410filling groups, 345Filter parameter
(get-childitemcommandlet), 211
filteringevent logs, 14LDAP queries, 358objects, 70-72
conditions, 70heterogeneous
pipeline content, 72parameter output, 28processes, 268RSS feeds, 301WMI objects, 146-147
flags (parameters), 420folders
copying, 212deleting, 212moving, 212public, 305renaming, 212
foreach-object commandlet,105, 235, 431
forests (Active Directory),366
format-byte commandlet,431
format-customcommandlet, 431
format-hex commandlet,431
format-list commandlet,431
format-table commandlet,431
format-wide commandlet,431
format-xml commandlet,244, 431
formatting XML files, 244free space (drives),
208-210FullControl right, 404
Gget-acl commandlet,
401, 431get-adobject commandlet,
314, 358, 431get-alias commandlet,
30, 432get-authenticodesignature
commandlet, 432get-bios commandlet, 432get-cdromdrive
commandlet, 432get-childitem commandlet,
432directory content, 210Filter parameter, 211include parameter, 211registry keys, 253
Index 463
get-clipboard commandlet,200, 432
get-commandcommandlet, 432
get-commandlet, 35get-computerinfo
commandlet, 432get-computername
commandlet, 432get-content commandlet,
206, 432binary files, 238files, reading, 229, 235
get-credentialcommandlet, 58, 432
get-culture commandlet,188, 432
get-currentusercommandlet, 432
get-datarow commandlet,396
get-datatable commandlet,396
get-date commandlet, 102, 432
get-dbconnectioncommandlet, 432
get-dbrow commandlet,433
get-dbtable commandlet,433
get-dhcpservercommandlet, 433
get-directorychildrencommandlet,362, 433
get-directoryentrycommandlet,362, 433
get-directoryvaluecommandlet,362, 433
get-disk commandlet, 206, 433
get-domaincontrollercommandlet,324, 433
get-eventlog commandlet,290, 433
get-executionpolicycommandlet, 433
get-exportedtypecommandlet,215, 433
get-fileversioninfocommandlet,215, 433
get-foregroundwindowcommandlet, 434
get-hash commandlet, 434get-help commandlet,
35, 434get-history commandlet,
186, 434get-host commandlet,
187, 434get-item commandlet, 434
file properties, 213registry keys, 254
get-itempropertycommandlet,255, 434
get-ITVisions commandlet,434
get-keyboard commandlet,434
get-location commandlet,206, 434
get-mailbox commandlet,303
get-mailboxdatabasecommandlet, 303
get-member commandlet,62, 66-68, 434
alias properties, 68code properties, 68methods, 64note properties, 67output, reducing, 69properties, 65property sets, 66script properties, 67
get-memorydevicecommandlet, 434
get-metadata commandlet,435
get-mountpointcommandlet, 435
get-networkadaptercommandlet, 435
get-peheader commandlet,215, 435
get-pfxcertificatecommandlet, 435
get-pipelineinfocommandlet, 60, 435
get-pointingdevicecommandlet, 435
get-privilege commandlet,435
get-process commandlet,11, 267-268, 435
get-process | out file commandlet, 55
get-process | out-printercommandlet, 55
get-processor commandlet,435
get-psdrive commandlet,83, 206, 435
get-psprovidercommandlet, 84, 435
get-pssnapin commandlet,435
464 Index
get-pssnapinhelpcommandlet, 435
get-random commandlet,435
get-reparsepointcommandlet, 435
get-service commandlet,272, 435
get-service i commandlet,13
get-shortpath commandlet,436
get-sounddevicecommandlet, 436
get-storagegroupcommandlet, 303
get-tabexpansioncommandlet, 436
get-tapedrive commandlet,436
get-terminalsessioncommandlet, 436
get-tracesourcecommandlet,173, 436
get-uiculture commandlet,188, 436
get-unique commandlet,436
get-usbcontrollercommandlet, 436
get-variable commandlet,436
get-videocontrollercommandlet, 436
get-wmiobjectcommandlet, 135,144, 436
hardware information,284
list parameter, 148
GetAccessRules( )method, 411
GetDrives( ) method, 206GetFactoryClasses( )
method, 375GetOwner( ) method, 417GetType( ) method, 93GPMC (Group Policy
ManagementConsole), 367, 450
GPMGMT component,367
graphical user interfaces,196
clipboard, 200input window, 196-198objects, displaying,
198-200group-object commandlet,
74, 436Group Policy Management
Console (GPMC),367, 450
grouping objects, 74-75groups
Active Directorycreating/filling, 345deleting users, 346members, 343-345
policies, 367classes, 367enumerating, 367, 369links, 369-372
WMI management, 314-315
Hhandling script errors,
125-127hardlinks, 217-218
hardwareinformation, viewing,
284-285printers
connections, 287listing all, 286print jobs, 287-289status, 286
hash tables, 106-108Hashtable class, 107help
commandlets, 35, 38get-commandlet, 35.NET classes, 38-40PSL, 90tool, 169
Help Editor website, 449heterogeneous pipeline
content, 72hexadecimal numbers, 96history
commands, 186-187WPS, 4-5
host information, 187-188HTML files, 251
IIADs interface, 317IDE, 156-157IEnumerable interface, 319IIS (Internet Information
Services), 305classes, 305virtual web servers
adding, 308-311deleting, 311listing, 307
IIsApplicationPoolclass, 305
IIsComputer class, 305IIsWebServer class, 305IIsWebService class, 305
Index 465
IIsWebVirtualDir class, 305
import-alias commandlet,436
import-bitmapcommandlet, 436
import-clixmlcommandlet, 436
import-csv commandlet,240, 436
import-dbcommandcommandlet, 437
importingCSV files, 240DataSets, 395
include parameter (get-childitemcommandlet), 211
indexed attributes (Active Directorysearches), 354
input boxes, 56input windows, 196-198InputBox( ) method, 56Install( ) method
(Win32_Product( )class), 263
installed services, viewing, 13
installingPowerShellPlus, 19printers, 287PSCX, 17services, 278software, 263WPS, 8-10
installutil.exe, 175IntelliSense
PowerShellPluscommandlet
names, 159commandlet
parameters, 160
.NET classes, 161path names, 160variables, 162
PrimalScriptclass names, 169commandlets, 168parameters, 168
interactive mode, 11, 14console window, 11event logs, filtering, 14IDE, 156installed services,
viewing, 13pipeline features, 13running processes,
viewing, 11tab completion, 13
interfacesADSI
architecture, 316deficiencies, 321-323directory services,
compared, 320DirectoryEntry class,
318-319integration, 316object model, 318property cache, 329search queries, 319
graphical user interfaces, 196
clipboard, 200input window, 196-198objects, displaying,
198-200IADs, 317IEnumerable, 319
intermediate steps(pipelines),viewing, 76
Internet InformationServices. See IIS
interpreter mode (WPSconsole), 154
inventory (software)script, 260-261searching, 260viewing, 259
invoke-dbcommandcommandlet, 396
invoke-expressioncommandlet,109, 437
invoke-historycommandlet, 437
invoke-item commandlet,437
invoke-scalardbcommandcommandlet, 437
J–KJoin( ) method, 102join-path commandlet, 437join-string commandlet,
102, 437joining
arrays, 105hash tables, 108strings, 102
junction points, 218-219
keys (registry)copying, 254creating, 254deleting, 254entries, 255-257hierarchy script, 115-117reading, 253-254
Kill( ) method (Processclass), 270
LLDAP queries
example, 350executing, 351filters, 358
466 Index
search example, 352search filters
website, 450syntax, 349-350user login name
searches, 353-354links
file system, 216Explorer, 216-217hardlinks, 217-218junction points,
218-219symbolic, 220
group policiescreating, 369-370deleting, 370-372
parameter flags, 420list parameter
get-eventlogcommandlet, 290
get-wmiobjectcommandlet, 148
ListDirectory right, 404listings
ACEsadding, 419deleting, 422-423details, 411
ACL transfers, 424-426Active Directory
domain controllers, 366domains/forests, 366search result
restrictions, 357user accounts,
passwords, 341Active Directory groups
creating, 345deleting members, 346listing members, 344member assignments,
346
Active Directory useraccounts
authentication, 341creating, 340deleting, 342moving, 343renaming, 342
binary files, 238COM classes
existing instances, 134instantiating, 133
database accessdata readers, 387-388provider-independent
command objects,384
www.IT-Visions.deextensions, 398-399
database connectionsMicrosoft Access, 381Microsoft SQL Server,
381-382Microsoft SQL Server
Express, 382provider-independent,
383DataSets
provider-independentexample, 394-395
provider-specific example, 392-393
dialog box user inputexample, 57
directory containerobjects, 331
directory entries, 332directory objects
customizing, 330fetching, 328properties, 331
directory service operations viawww.IT-Visions.decommandlets,363-364
downloading files viaHTTP, 300
downloading/filteringRSS feeds, 301
drive free space, viewingDriveInfo class, 208Win32_LogicalDisk
class, 209-210drive names, 210e-mail, sending, 302executable files,
viewing, 215files
date and time, configuring, 214
share permissions, creating, 226-228
shares, creating, 224,230-232
formatted output, 55get-wmiobject
commandlet, 144group policies
enumerating, 368-369links, 370-372
input windows, 196-198LDAP
searches, executing, 352user login name
search, 354networks, configuring,
297-298objects, displaying,
198-200organizational units,
creating, 347print jobs, canceling, 288
Index 467
protocol entries, fetching, 291
registry example, 258scripts
dot sourcing, 118error testing example,
123-125registry key hierarchy,
115-117services
configuration,customizing, 278
enumerating, 272SIDs
displaying, 414SDDL names, 416well-known, 415
softwareinstallations, testing,
265-266installing, 264inventory script,
260-261inventory solution with
WPS, 8inventory solution with
WSH, 5-7searching inventory,
260uninstalling, 264
stringscustomizing, 100joining, 102splitting, 101
subroutines, 112system owners,
reading, 418text files
reading, 235writing to, 236
user accounts, creating, 14
user input, 56user profiles
PSCX, 190-195script, 188
variable resolution within a string, 99
virtual web servers information,viewing, 308
waiting for process ending, 271
websites, creating fromCSV files, 309-311
WMIclasses, instantiating,
149date format
conversions, 145XML files
customizing, 247fetching, 242
loadingassemblies, .NET
classes, 131snap-ins, WPS console,
175-176locking variables, 95logical operators, 72
Mmailboxes (Exchange
Server)attributes, 304creating, 303deactivating, 304listing, 303managing, 303-304moving, 304
MailMessage class, 302ManagementBaseObject
class, 135
ManagementClassclass, 135
ManagementDateTime-Converter class, 145
ManagementObjectclass, 135
mass creation, file shares,229-232
measure-commandcommandlet,173, 437
measure-objectcommandlet, 76, 437
measuring execution time, 173
methods, 64AddPrinterConnection( ),
287AppendChild( ), 246calling, 64Change( ), 278CommitChanges( ), 329ConvertToDateTime( ),
145CreateElement( ), 246DeleteTree( ), 342DownloadString( ), 300Exists( ), 327GetAccessRules( ), 411GetDrives( ), 206GetFactoryClasses( ), 375GetOwner( ), 417GetType( ), 93InputBox( ), 56Install( ), 263Join( ), 102Kill( ), 270object pipelines, 45-46PurgeAccessRules( ), 421RefreshCache( ), 329
468 Index
RemoveAccessRule( ),421
SelectNodes( ), 229, 244SelectSingleNode( ), 244SetInfo( ), 317Slit( ), 101String class, 99Subtract( ), 103ToDateTime( ), 145ToString( ), 60Uninstall( ), 264WM classes, 142, 144
Modify right, 404move-item commandlet,
206, 212, 437move-itemproperty
commandlet, 437moving
files/folders, 212mailboxes, 304user accounts, 343
multidimensionalarrays, 106
multivalued attributes(Active Directorysearches), 355-356
Nname resolution, 299names
drives, 210event logs, 290files/folders, 212SDDL, 416-417
navigatingActive Directory, 361commandlets, 84drives, defining, 87-88paths, 85-86registry, 83-84
.NET3.0 Redistributable
package website, 10classes, 129
assemblies, loading, 131constructor
parameters, 130enumerations, 132help, 38-40instances, creating, 130library documentation
for FileSystemRightsenumerationwebsite, 450
object analysis, 132static members, 130
Community website, 449regular expressions
website, 450tools and software
components refer-ence website, 449
NetCmdlets from nsoftware website,450
networkingconfiguring, 296-298drives, 210e-mail, sending, 302Exchange Server 2007,
302basic operations, 302databases, listing, 303functionality,
testing, 303mailboxes, 303-304public folder
management, 305storage groups, 303
file retrieval from HTTPservers, 300-301
IIS, 305classes, 305virtual web servers,
307-311name resolution, 299pinging computers, 295
new-alias commandlet, 30, 437
new-hardlink commandlet,218, 437
new-item commandlet,206, 437
registry keys, 254text files, creating, 236
new-itempropertycommandlet,256, 437
new-junction commandlet,218, 437
new-mailboxdatabasecommandlet, 303
new-object commandlet,437
new-psdrive commandlet,438
new-service commandlet,278, 438
new-shortcut commandlet,217, 438
new-storagegroupcommandlet, 303
new-symlink commandlet,220, 438
new-timespancommandlet,103, 438
new-variable commandlet,438
nonterminating errors, 122note properties, 67nouns (commandlets), 29
Index 469
numbers, 96-98assigning to untyped
variables, 96hexadecimal, 96random, 98
Oobject model (DataSets),
390objects
castrating, 73-74comparing, 78displaying, 198-200filtering, 70-72
conditions, 70heterogeneous
pipeline content, 72grouping, 74-75.NET classes, 132orientation, pipelining,
44pipelines, 44
HTML files, 251methods, 45-46parameters, 46XML documents, 248
sorting, 74WMI
accessing, 137-138adapter, 139analysis, 140filtering/selecting,
146-147ObjectSecurity class, 406operators, 72, 108-109organizational units,
creating, 346-347out-clipboard
commandlet, 438out-default commandlet,
51, 438
out-file commandlet, 55,236, 438
out-host commandlet, 51, 438
out-null commandlet, 438out-printer commandlet,
55, 287, 438out-string commandlet,
438output, 49
get-membercommandlet
alias properties, 68code properties, 68methods, 64note properties, 67properties, 65property sets, 66reducing, 69script properties, 67
mixing literals and variables, 54
printing, 55single values, 53-54standard, 51-53
pagewise, 51restricting, 52
suppressing, 55text files, 55
Pp parameter (out-host
commandlet), 51pagewise output, 51parameters, 26-27
calculated, 27-28case sensitivity, 29debugging, 171ErrorAction, 125-127Filter, 211filtering output, 28
flags, linking, 420include, 211LDAP queries, 349list
get-eventlogcommandlet, 290
get-wmiobjectcommandlet, 148
.NET class constructors,130
object pipelines, 46p, 51placeholders, 29quotation marks, 26sequence, 27start-process
commandlet, 270parentheses ( ) in
methods, 64passwords (user
accounts), 340paths, 85-86, 323-325pausing
print jobs, 288scripts, 122
performance counters,292-293
periods of time, 103permissions (file shares),
225-228ping-host commandlet,
296, 438pinging computers, 295Pipeline Processor, 47-49pipelines
| (vertical line), 43calculations, 76classic commands, 46complex, 48-49content, analyzing, 59
alias properties, 68code properties, 68
470 Index
ETS, 69-70get-member
commandlet, 62, 66-69
get-pipelineinfocommandlet, 60
methods, 64note properties, 67properties, 65property sets, 66script properties, 67
creating, 43features, 13heterogeneous
content, 72intermediate steps, view-
ing, 76objects, 44
castrating, 73-74comparing, 78filtering objects, 70-72grouping, 74-75HTML files, 251methods, 45-46orientation, 44parameters, 46sorting, 74XML, 248
output, 49printing, 55single values, 53-54standard, 51-53suppressing, 55text files, 55
Pipeline Processor, 47-49
ramifications, 78user input, 56
authentication dialogboxes, 58
dialog boxes, 57input box, 56
placeholders, 29plus sign (+) operator,
54, 108policies
execution, 119group, 367
classes, 367creating links, 369-370deleting links, 370-372enumerating, 367-369
pop-location commandlet,438
PowerShellAnalyzer, 164Community Extensions.
See PSCXdocumentation
website, 449download website, 449Help, 169IDE, 156-157Pipeline Processor,
47-49remoting website, 449Script Language.
See PSLPowerShell
2.0, 445-447PowerShellPlus, 19, 158
debugging, 21, 163functions, 158installing, 19IntelliSense
commandlets, 159-160.NET classes, 161path names, 160variables, 162
PrimalScript,compared, 166
testing, 20variables, viewing all, 164website, 19
PowerShellPlus Editor, 22PowerTab, 156predefined variables, 93PrimalScript, 165
IntelliSenseclass names, 169commandlets, 168parameters, 168
PowerShellPlus,compared, 166
website, 166WPS script output, 167
printersconnections, 287jobs, 287-289listing all, 286output, 55print jobs, 287-289status, 286
priority parameter (start-processcommandlet), 270
processes, 267ending, 270enumerating, 267-268filtering, 268running, 11starting, 269-270waiting for ending, 271
product activation settings, 282
profiles, 189-195programming directory
services, 325ADSI property cache, 329binding meta objects to
directory entries,325-326
container objects, 331directory entries
attributes, 328-329creating, 332
Index 471
deleting, 332existence, checking, 327
impersonation, 327object properties, 330
properties, 65alias, 68code, 68directory objects, 330files
customizing, 214date/time information,
214viewing, 213
note, 67PSSnapIn, 179script, 67WMI classes, 142-144
Property attribute(DirectoryEntryclass), 318
property sets, 66Prosser, Karl, 164provider factories, 384providers, 83-84
independent data access,382-383
listing of, 84viewing, 84
PSCX (PowerShellCommunityExtensions), 17, 181
Active Directory navigation, 361
commandlets, 181-182downloading, 17executable files
commandlets, 214installing, 17LDAP filters, 358testing, 18website, 181, 449
PSL (PowerShell ScriptLanguage), 89
arrays, 105-106associative, 106-108declaring, 105defining, 105joining, 105listing, 105multidimensional, 106
command separation, 90comments, 90control structures,
110-112data types, 92date and time, 102-103
periods of time, 103remote computers, 104setting, 104
hash tables, 106-108accessing, 107defining, 107joining, 108
help, 90numbers, 96-98
assigning to untypedvariables, 96
hexadecimal, 96random, 98
operators, 108-109strings, 99
customizing, 100joining, 102splitting, 101
variables, 91constant values, 95data types, 91-93declaring, 91example, 94predefined, 93resolution, 95
PSSnapIn property(CmdletInfoclass), 179
public folders, managing, 305
PurgeAccessRules( )method, 421
push-locationcommandlet, 438
Qqueries
LDAPexample, 350executing, 351filters, 358search example, 352syntax, 349-350user login name
searches, 353-354WQL, 147
Questextensions (Active
Directory), 365Management Shell for
Active Directory,183-184
quotation marks (“ ”) inparameters, 26
Rramifications (pipelines), 78random numbers, 98Read right, 404read-host commandlet,
56, 438ReadAndExecute right, 404ReadAttributes right, 404ReadData right, 405ReadExtendedAttributes
right, 405
472 Index
readingACEs, 410-411ACLs, 408-409binary files, 238directory entry
attributes, 328registry keys, 253-255system owners, 417text files, 235-236XML files, 241
ReadPermissions right, 405recovery settings, 283reflection mechanism, 44RefreshCache( )
method, 329registry, 253
data types, 257drives, defining, 255example, 257-258keys
copying, 254creating, 254deleting, 254entries, 255-257hierarchy script,
115-117reading, 253-254
navigating, 81commandlets, 84drives, 83-84providers, 83-84
regular expressions, 71relational operators, 72remote computers, date
and time, 104remove-directoryentry
commandlet,362, 438
remove-item commandlet,206, 212, 254, 438
remove-itempropertycommandlet,257, 438
remove-mountpointcommandlet, 439
remove-psdrivecommandlet, 439
remove-pssnapincommandlet, 439
remove-reparsepointcommandlet, 439
remove-variablecommandlet, 439
RemoveAccessRule( )method, 421
rename-item commandlet,206, 212, 439
rename-itempropertycommandlet, 439
renamingfiles/folders, 212users, 342
resize-bitmapcommandlet, 439
resolution (variables), 95resolve-assembly
commandlet,215, 439
resolve-host commandlet,299, 439
resolve-path commandlet,439
resources (security classes), 407
restart-servicecommandlet,277, 439
restricting output, 52resume-service
commandlet, 439retrieving files from HTTP
servers, 300-301rights (access), 403-406RSS feeds, 301running processes,
viewing, 11
Sschemas (Active
Directory), 338script mode, 14-15, 156scripts
DataSet providersindependent example,
394-395specific example,
391-393debugging, 21digital signatures,
120-121dot sourcing, 118errors, 122
creating, 128handling, 125-127history, 128standard reactions, 127trap blocks, 128trapping example,
123-125Exchange Server scripts
website, 451pausing, 122properties, 67registry key hierarchy,
115-117security, 118-119software inventory,
260-261starting, 117user accounts,
creating, 14SCVMM (System Center
Virtual MachineManager), 185
SDDL (Security DescriptorDefinitionLanguage), 416
ACLs, configuring, 425-426
names, 416-417
Index 473
SDK website, 450SDs (security descriptors),
225, 402search queries (ADSI), 319searching
Active Directory, 314indexed attributes, 354multivalued attributes,
355-356result restrictions, 357star operator, 356
software inventory, 260text files, 237XML files, 244
security, 402access rights, 403-406ACLs, 402
ACEs, 402adding ACEs, 418-419configuring, 425-426deleting ACEs,
421-423reading ACEs,
410-411transferring, 424
classes, 406control holders, 408inheritance
hierarchy, 406ObjectSecurity, 406reading ACLs, 408-409resources, 407
descriptors (SDs), 225, 402
owners, reading, 417scripts, 118-119SIDs
displaying, 414SDDL names, 416-417well-known, 414-416
user accounts, 402Security Descriptor
Definition Language.See SDDL
security descriptor (SDs),225, 402
security identifiers. See SIDs
select-object commandlet,70, 73, 439
select-string commandlet,237, 439
select-xml commandlet,244-246, 439
selecting WMI objects, 146
SelectNodes( ) method(XMLDocumentclass), 229, 244
SelectSingleNode( )method(XmlDocumentclass), 244
semicolons (;) in commands, 90
send-smtpmailcommandlet,302, 439
sending e-mail, 302sequence (parameters), 27serial numbers
(computers), 282servers
HTTP, 300-301SQL, 376virtual web servers
adding, 308-311deleting, 311listing, 307
servicesattributes, 278configuration,
customizing, 278-279dependent, 274-276directory, 325
access, 313ADSI. See ADSI
binding meta objectsto directory entries,325-326
container objects, 331directory entries, 332directory entry
attributes, 328-329directory entry exis-
tence, checking, 327impersonation, 327object properties, 330paths, 323-325www.IT-Visions.de
commandlets,362-364
enumerating, 272-273installed, viewing, 13installing, 278starting, 276-277stopping, 277
set-acl commandlet, 401, 440
set-alias commandlet, 30, 440
set-authenticodesignaturecommandlet,120, 440
set-clipboard commandlet,200, 440
set-content commandlet,206, 440
binary files, 238text files, writing, 236
set-datarow commandlet,396
set-datatable commandlet,396
set-date commandlet, 104, 440
set-dbtable commandlet,440
set-directoryvaluecommandlet,362, 440
474 Index
set-distributiongroupcommandlet, 304
set-executionpolicycommandlet,119, 440
set-filetime commandlet,214, 440
set-foregroundwindowcommandlet, 440
set-item commandlet, 206, 440
set-itemproperty com-mandlet, 214, 440
set-location commandlet,206, 254, 441
set-privilege commandlet,441
set-psdebug commandlet,173, 441
set-service commandlet,278, 441
set-tracesourcecommandlet,173, 441
set-variable commandlet,441
set-volumelabelcommandlet,210, 441
SetInfo( ) method, 317settings (computers),
281-283SharePoint Provider
website, 449SIDs (security
identifiers), 402displaying, 414SDDL names, 416-417well-known, 414-416
signing scripts, 120-121single value output, 53-54SMTP (Simple Mail Transfer
Protocol), 302
SmtpClient class, 302snap-ins
adding, 175commandlets, 179listing, 178loading in WPS console,
175-176Snover, Jeffrey, 117software, 259
autostart, 263installed list of, 262installing, 263inventory
script, 260-261searching, 260solution with WPS, 8solution with WSH,
5-7viewing, 259
not installed withWindows Installer,262
uninstalling, 264versions, viewing, 282
sort-object commandlet,74, 441
sorting objects, 74Split( ) method, 101split-path commandlet,
441split-string commandlet,
101, 441splitting strings, 101SQL Servers, listing avail-
able, 376standard output, 51-53
pagewise, 51restricting, 52
star operator (*), 108, 356start-process commandlet,
269-270, 441start-service commandlet,
277, 441
start-sleep commandlet,122, 441
start-tabexpansioncommandlet, 441
start-transcriptcommandlet, 441
startingprocesses, 269-270scripts, 117services, 276-277
static members.NET classes, 130WMI classes, 144
step-by-step debugging,173
stop-process commandlet,270, 441
stop-service commandlet,277, 441
stop-terminalsessioncommandlet, 441
stop-transcriptcommandlet, 441
stopping services, 277storage limitations (public
folders), 305String class, 99strings, 99
customizing, 100joining, 102representation, 60splitting, 101
subroutines, 112Subtract( ) method, 103suspend-service
commandlet, 442symbolic links, 220Synchronize right, 405syntax
commandlets, 26LDAP queries, 349-350
Index 475
logical operators, 72regular expressions, 71relational operators, 72
System Center VirtualMachine Manager(SCVMM), 185
system information, 187-188
system owners, reading, 417
System.Managementobject model, 135
System.Managementnamespacedocumentationwebsite, 450
Ttab completion, 13, 153TakeOwnership right, 405targets (junction
points), 219terminating errors, 122test-assembly commandlet,
214, 442test-dbconnection
commandlet,396, 442
test-path commandlet, 442test-xml commandlet,
243, 442testing
Exchange Server 2007functionality, 303
PowerShellPlus, 20-22PSCX, 18
text filescontent, deleting, 236reading, 235-236searching, 237writing to, 236-237
time and date, 102-103periods of time, 103remote computers, 104setting, 104
TimeSpan class, 103ToDateTime( )
method, 145ToString( ) method, 60trace-command
commandlet, 442tracing, 173transferring ACLs, 424Traverse right, 405tree-object commandlet,
78, 442trial and error website, 451type indicators (WMI
classes), 139
UUninstall( ) method
(Win32_Productclass), 264
uninstallingsoftware, 264WPS, 10
update-formatdatacommandlet, 442
update-typedatacommandlet, 442
user accountsActive Directory,
335-338authentication, 341creating, 339-340deleting, 342moving, 343passwords, 340renaming, 342
creating, 14security, 402
user administrationActive Directory
authentication, 341deleting users, 342moving users, 343renaming users, 342user accounts, 339-340user class attributes,
335-338WMI, 314-315
usersadding to groups, 345deleting from
groups, 346input, 56
authentication dialogboxes, 58
dialog boxes, 57input box, 56
object user interfacemapping website, 450
profile script, 188
Vvariables, 91
constant values, 95data types, 91-93declaring, 91example, 94predefined, 93resolution, 95
VBScript command con-versions website, 451
verbose parameter, 171-172
vertical line (|) forpipelines, 43
viewingcommandlets list, 35computer settings,
281-283directory content,
210-212
476 Index
drive free space (file system), 208, 210
drives list, 206-207environment
variables, 283executable files, 215file properties, 213hardware information,
284-285installed services, 13objects, 198-200pipeline intermediate
steps, 76providers, 84running processes, 11SIDs, 414software inventory,
259, 262virtual web servers
adding, 308-311deleting, 311listing, 307
Vista user account control, 155
Wwaiting for process
ending, 271WebClient class, 300websites
Active Directoryschema, 450
AD AccessChange/Break inRC2, 449
Cmdlet developmentguidelines, 450
Cmdlet help, 450data providers, 375ETS, 450Exchange Management
Shell, 451
Exchange Server scripts, 451
Group PolicyManagementConsole with ServicePack 1, 450
Help Editor, 449LDAP search filters, 450.NET Framework
3.0 Redistributablepackage, 10
class library documentation forFileSystemRightsenumeration, 450
Community, 449Framework regular
expressions, 450tools and software
componentsreference, 449
NetCmdlets from nsoftware, 450
PowerShellAnalyzer, 165documentation, 449download, 449Help, 169remoting, 449
PowerShellPlus, 19PrimalScript, 166PSCX, 17, 181, 449SDK, 450SharePoint Provider, 449System.Management
documentation, 450trial and error, 451user object user
mapping, 450VBScript command
conversions, 451Windows PowerShell
graphical help file, 449
WMI schema class reference, 450
WPS download, 9www.IT-Vision.de WPS
extensions, 183well-known security
principals, 414-416WhatIf parameter, 171where-object commandlet,
70, 442wildcards, 29Win32_Computersystem
class, 281Win32_Desktop class, 315Win32_LogicalDisk class
drive free space, viewing, 209-210
drives, viewing, 207Win32_NetworkAdapter-
Configurationclass, 296
Win32_NTLogEvent class, 291
Win32_Operating Systemclass, 281
Win32_PerfRawData class, 292
Win32_Product class, 259Win32_Service class, 277Win32_Share class, 221Win32_StartupCommand
class, 263Win32_Trustee class, 226windows
console, 11input, 196, 198
Windows FormsPropertyGridcontrol, 198
Windows PowerShell. See WPS
Index 477
WMI (WindowsManagementInstrumentation), 135
classes, 135available, listing, 148collections,
accessing, 146IIsApplicationPool,
305IIsComputer, 305IIsWebServer, 305IIsWebService, 305IIsWebVirtualDir, 305instances, creating, 149object access, 137-138object adapter, 139object analysis, 140object filtering/
selecting, 146-147properties/methods,
142-144queries, 147static class
members, 144System.Management
object model, 135type indicators, 139Win32_Computer-
system, 281Win32_Desktop, 315Win32_LogicalDisk,
207-210Win32_NetworkAdapter
Configuration, 296Win32_NTLogEvent,
291Win32_Operating-
System, 281Win32_PerfRawData,
292Win32_Product, 259Win32_Service, 277
Win32_Share, 221Win32_Startup-
Command, 263Win32_Trustee, 226WPS support, 136
date format conversions, 145
groups, managing, 314-315
objectsaccessing, 137-138adapter, 139analysis, 140
schema class referencewebsite, 450
users, managing, 314-315WMI Query Language
(WQL), 147WorkingDirectory parame-
ter (start-processcommandlet), 270
WPS (Windows PowerShell).See also scripts
definition, 3benefits, 5console, 151
command history, 186-187
command mode, 154functions, 152interpreter mode, 154PowerTab, 156snap-ins, loading,
175-176tab completion, 153Vista user account
control, 155downloading, 8graphical help file
website, 449history, 4-5installing, 8-10
interactive mode, 11-14console window, 11event logs, filtering, 14installed services,
viewing, 13pipeline features, 13running processes,
viewing, 11tab completion, 13
script mode, 14-15software inventory
solution, 8uninstalling, 10WMI support, 136
WQL (WMI QueryLanguage), 147
Write right, 405write-bzip2 commandlet,
442write-clipboard
commandlet,200, 442
write-debug commandlet,442
write-error commandlet,53, 442
write-gzip commandlet,442
write-host commandlet,53, 442
write-output commandlet,443
write-progresscommandlet, 443
write-tar commandlet, 443write-verbose
commandlet, 443write-warn commandlet,
53write-warning
commandlet, 443
478 Index
write-zip commandlet,220, 443
WriteAttributes right, 405WriteData right, 406WriteExtendedAttributes
right, 406writing
binary files, 238directory entry
attributes, 329text files, 236-237
WSH software inventorysolution, 5, 7
www.IT-Visions.de extensions, 183
Active Directory, 362-364
database access, 396-399
X–ZXML files, 241
checking, 242-243converting to XHTML
files, 249customizing, 246DataSet exports/
imports, 395formatting, 244object pipeline, 248reading, 241searching with XPath,
244XMLDocument class,
229, 244XPath, 244