Many of the designations used by manufacturers and sellers to distinguish their products are Editor-in-Chief claimed as trademarks. Where those designations appear in this book, and the publisher was Karen Gettman aware of a trademark claim, the designations have been printed with initial capital letters or in all capitals. Executive Editor Neil Rowe The author and publisher have taken care in the preparation of this book, but make no expressed or implied warranty of any kind and assume no responsibility for errors or omissions. No liability Development is assumed for incidental or consequential damages in connection with or arising out of the use of Editor the information or programs contained herein. Mark Renfrow The publisher offers excellent discounts on this book when ordered in quantity for bulk purchases Managing Editor or special sales, which may include electronic versions and/or custom covers and content partic- Kristy Hart ular to your business, training goals, marketing focus, and branding interests. For more informa- tion, please contact: Project Editor U.S. Corporate and Government Sales Betsy Harris (800) 382-3419 Copy Editor [email protected] Keith Cline For sales outside the United States please contact: Indexer International Sales Publishing Works, [email protected] Inc. Visit us on the Web: www.informit.com/aw Proofreader of Congress Cataloging-in-Publication Data Paula Lowell Schwichtenberg, Holger. Technical Editor Essential PowerShell / Holger Schwichtenberg. Tony Bradley . cm. ISBN 978-0-672-32966-1 Publishing 1. Windows PowerShell (Computer programming language) 2. Command languages Coordinator (Computer science) 3. Scripting languages (Computer science) 4. Systems programming Cindy Teeters (Computer science) 5. Windows (Computer file) I. . QA76.73.W56S39 2008 Cover Designer 005.4’2—dc22 Gary Adair 2008020010 Compositor Copyright © 2008 by Pearson Education, Inc. Nonie Ratcliff 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, Inc Rights and Contracts Department 501 Boylston Street, Suite 900 Boston, MA 02116 Fax (617) 671 3447 ISBN-13: 978-0-672-32966-1 ISBN-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 edition for 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 and wherever 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 e- [email protected]. PREFACE

Windows PowerShell is one of the most amazing products Microsoft has released 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 commands and for (WSH). PowerShell copies a lot of good features from UNIX shells and combines them with the power of the .NET Framework. In contrast to WSH, PowerShell enables consistent, straightforward, command-line system administration that does not require much software development knowledge. Unfortunately, in the first version of PowerShell, the number of high- level commands is limited. For many tasks, lower-level concepts are required, especially the .NET Framework and Windows Management Instrumentation (WMI).

What Does This Book Cover?

This book covers the standard PowerShell commandlets, additional free commandlets (for example, PowerShell Community Extensions), and the direct use of classes from the .NET Framework, the (COM), WMI, and the Service Interface (ADSI). Because PowerShell is an extensive topic, this book cannot provide an exhaustive reference of all PowerShell commands and solutions for all pos- sible administrative tasks. However, you will find a concise introduction to the most common command and scenarios. For more detailed information about PowerShell, refer to the Microsoft documentation for PowerShell, WMI, ADSI, and the .NET Framework (approximately 100,000 pages) as an additional source.

xv xvi Preface

Who Should Read This Book?

The primary target audience comprises Windows administrators seeking a method of automated system administration that is more powerful than the classic but less complex than WSH and the associated COM components. After reading this book, administrators will be able to use PowerShell as their day-to-day command-line interface for all admin- istrative tasks. As a prerequisite, aside a good knowledge of the Windows operation system, 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 easier to understand than others. The 24 chapters are split into two parts:

■ Part I: Getting Started with PowerShell. Part I introduces the PowerShell architecture, all basic concepts (such as pipelining and navigation), the PowerShell Script Language, and the tools you should know. ■ Part II: Windows PowerShell in Action. Part II covers PowerShell script solutions for day-to-day administrative tasks related to Windows services and Windows application, such as file system, processes, event logs, registry, networking, printers, docu- ments, databases, Active Directory, and software installation. Each chapter 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.de PowerShell Extensions 2.0. You will also find a short preview of the next version of Windows PowerShell (Version 2.0). Throughout the text, you will find codes that match up to codes in Appendix C, “Bibliography.” These codes are encased in brackets (for example, [MS01]). The appendix lists the code, the correlating subject, and Preface xvii

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 the line 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 this book and the option to offer feedback to the author. CHAPTER 1

FIRST STEPS WITH WINDOWS POWERSHELL

In this chapter: What Is Windows PowerShell? ...... 3 Downloading and Installing PowerShell Community Extensions ...... 16 Testing the PowerShell Extensions ...... 18 Downloading and Installing the PowerShellPlus ...... 19 Testing the PowerShell Editor ...... 20

This chapter introduces Windows PowerShell and helps you set up your environment. In addition, the chapter provides a few easy examples that demonstrate how to use PowerShell.

What Is Windows PowerShell?

Windows PowerShell (WPS) is a new .NET-based environment for console-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, and Windows Management Instrumentation (WMI) ■ Robust interaction between commandlets through pipelining based on typed objects

3 4 Chapter 1 First Steps with Windows PowerShell

■ A common navigation paradigm for different hierarchical or flat information stores (for example, file system, registry, certificates, Active Directory, and environment variables) ■ An easy-to-learn, but powerful with weak and strong 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 the last 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 History The DOS-like command-line survived many Windows versions in almost unchanged form. With WPS, Microsoft now provides a successor that does not just compete with UNIX shells, it surpasses them in robust- ness and elegance. WPS could be called an adaptation of the concept of UNIX shells on Windows using the .NET Framework, with connections to WMI. 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 the associated component libraries hard to learn. Even during the development of Windows 2003, Microsoft admitted that it had asked UNIX administrators how they administer their . The short-term result was a large number of additional command-line tools included in Windows Server 2003. However, the long- term goal was to replace the DOS-like command-line window of Windows with a new, much more powerful shell. Upon the release of the Microsoft .NET Framework in 2002, many were expecting a “WSH.NET.” However, Microsoft stopped the development of a new WSH for the .NET Framework because it foresaw that using .NET-based programming languages such as C# and Visual Basic .NET would require administrators to know even more about object- oriented software development. What Is Windows PowerShell? 5

Microsoft recognized the popularity of and satisfaction with UNIX

shells and decided to merge the pipelining concept of UNIX shells with F 1.

the .NET Framework. The goal was to develop a new shell that was sim- IRST

ple to use but nearly as robust as a .NET program. The result: WPS. S In the first beta version, the new shell was presented under the code WITH TEPS name Monad at the Professional Developer Conference (PDC) in October

2003 in Los Angeles. After the intermediate names Microsoft Shell (MSH) W and Microsoft Command Shell, the shell received its final name, INDOWS PowerShell, in May 2006. The final version of WPS 1.0 was released on P

November 11, 2006 at TechEd Europe 2006. OWER S HELL NOTE The main architect of WPS 1.0 was Jeffrey Snover. He is always willing to discuss his “baby” and answer questions. At large international Microsoft technical conferences, such as the Professional Developer Conference (PDC) and TechEd, you can easily find him; he is the only person at the Microsoft booths wearing 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 and the new WPS. An inventory script for software is to be provided that will read the installed MSI packages using WMI. The script will get the information from several computers and summarize the results in a CSV file (softwareinventory.csv). The names (or IP addresses) of the computers to be 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 in just 13 lines (Listing 1.2). If you do not want to include comments and parameterizing, you need just one line (Listing 1.3).

Listing 1.1 Software Inventory Solution 1: WSH

Option Explicit

' --- Const InputFileName = "computers.txt" Const OutputFileName = "softwareinventory.csv" (continues) 6 Chapter 1 First Steps with Windows PowerShell

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 What Is Windows PowerShell? 7

objTX.Close .F 1. ' === Get Software inventory for one computer Sub GetInventory(Computer) IRST S ESWITH TEPS Dim objProducts Dim objProduct

Dim objWMIService W INDOWS

' --- Access WMI P

Set objWMIService = GetObject("winmgmts:" &_ OWER "{impersonationLevel=impersonate}!\\" & Computer &_ S "\root\cimv2") HELL ' --- 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

' === Print 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 8 Chapter 1 First Steps with Windows PowerShell

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 WPS Windows Server 2008 is the first operating system that includes WPS on the DVD. However, it is an additional feature that can be installed through Add Feature in the Windows Server 2008 Server Manager. WPS can be downloaded (see Figure 1.1) and installed as an add-on to the 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 What Is Windows PowerShell? 9

■ Windows Server 2003 for x64 with Service Pack 1

■ Windows Server 2003 for Itanium with Service Pack 1 F 1. ■ for x86 IRST ■

Windows Vista for x64 S ESWITH TEPS

Note that WPS is not included in Windows Vista, although Vista und

WPS were released on the same day. Microsoft decided not to ship any W .NET-based applications with Vista. Only the .NET Framework itself is INDOWS part of Vista. P OWER S

POWERSHELL DOWNLOAD PAGE www.microsoft.com/ HELL windowsserver2003/technologies/management//download.mspx

Figure 1.1 WPS download website 10 Chapter 1 First Steps with Windows PowerShell

WPS requires that .NET Framework 2.0 or later be installed before running WPS setup. Because Vista ships with .NET Framework 3.0 (which is a true superset of 2.0), no .NET installation is required for it. However, on Windows XP and Windows Server, you must install .NET Framework 2.0, 3.0, or 3.5 first (if they are not already installed by another application).

MICROSOFT .NET FRAMEWORK 3.0 REDISTRIBUTABLE PACKAGE www.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 cannot change this folder during setup.

TIP If for any reason you want to uninstall WPS, note that WPS is considered a software update to the Windows operating system (that is, not a normal applica- tion). Therefore, in the Add or Remove Programs applet, it is not listed 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 Figure 1.2). On Windows XP and Windows Server 2003, you must check the Show Updates check box to see the WPS installation.

Taking WPS for a Test Run This section includes some commands to enable you to try out a few WPS features. WPS has two modes, interactive mode and script mode, which are covered separately. What Is Windows PowerShell? 11 .F 1. IRST S ESWITH TEPS W INDOWS P OWER S HELL

Figure 1.2 The uninstall option for WPS is difficult to find. (This screenshot is from Windows Server 2003.)

WPS in Interactive Mode First, you’ll use WPS in interactive mode. Start WPS. An empty WPS console window will display (see Figure 1.3). At first glance, you might not see much difference between it and the traditional . However, there is much more power in WPS, as you will soon see. At the command prompt, type get-process and then press the Return 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 distinguish between uppercase and lowercase letters in commandlet names. 12 Chapter 1 First Steps with Windows PowerShell

Figure 1.3 Empty WPS console window

Figure 1.4 The Get-Process commandlet output

At the command prompt, type get-service i*. A list of all installed services with a name that begins with the letter I on your computer will What Is Windows PowerShell? 13

display (see Figure 1.5). This was your first use of a commandlet with

parameters. F 1. IRST S ESWITH TEPS W INDOWS P OWER

Figure 1.5 A filtered list of Windows services S HELL

Type get- and then press the Tab key several times. You will see WPS cycling through all commandlets that start with the verb get. Microsoft calls this feature tab completion. Stop at Get-Eventlog. When you press Enter, 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 Application event log.

Figure 1.6 WPS prompts for a required parameter.

The last example in this section introduces you to the pipeline features of WPS. Again, we want to list entries from a Windows event log, but this time we want to get only some entries. The task is to get the most recent ten events that apply to printing. Enter the following command, which consists 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 the first ten entries. This is the correct behavior because the first commandlet 14 Chapter 1 First Steps with Windows PowerShell

(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.

Figure 1.7 Filtering event log entries

WPS in Script Mode Now it’s time to try out PowerShell in script mode and incorporate a WPS script. A WPS script is a text file that includes commandlets/elements of PowerShell Script Language (PSL). The script in this example creates a new 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" What Is Windows PowerShell? 15

# Access to Container using the COM library ➥"Active Directory Service Interface (ADSI)" .F 1. $Container = [ADSI] "WinNT://$Computer" IRST S

# Create User WITH TEPS $objUser = $Container.Create("user", $Accountname) $objUser.Put("Fullname", $Name)

$objUser.Put("Description", $Description) W # Set Password INDOWS $objUser.SetPassword($Password) P

# Save Changes OWER $objUser.SetInfo() S HELL "User created: $Name"

Save the text file with the name createuser.ps1 into the directory c:\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, not allowed in WPS (see Figure 1.8). This is not a bug; it is a security feature. (Remember the Love Letter worm for WSH?)

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) will need a digital signature from a trusted script author. Later in this book you learn 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 16 Chapter 1 First Steps with Windows PowerShell

Then, start the script again (see Figure 1.9). Now you should see a message that the user account has been created (see Figure 1.10).

Figure 1.9 Running your first script to create a user account

Figure 1.10 The newly created user account

Downloading and Installing PowerShell Community Extensions

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). Downloading and Installing PowerShell Community Extensions 17

PowerShell Community Extensions (PSCX) is an open source project

(see Figure 1.11) that provides additional functionality with commandlets F 1.

such as Get-DhcpServer, Get-DomainController, Get-MountPoint, IRST Get-TerminalSession Ping-Host Write-GZip , , , and many more. S Microsoft leads this project, but any .NET software developer is invited to WITH TEPS contribute. New versions are published on a regular basis. At the time of

this writing, version 1.1.1 is the current stable release. W INDOWS

DOWNLOAD POWERSHELL COMMUNITY EXTENSIONS P www..com/PowerShellCX OWER S HELL PSCX is provided as a setup routine that should be installed after WPS has been installed successfully.

Figure 1.11 PowerShell Community Extension website 18 Chapter 1 First Steps with Windows PowerShell

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.

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 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 19 .F 1. IRST S ESWITH TEPS W INDOWS P OWER S HELL

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 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. 20 Chapter 1 First Steps with Windows PowerShell

Testing the PowerShell Editor

The 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 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 the IntelliSense. If you enter Get-P, you will see a drop-down list of the avail- able commandlets that start with these letters.

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 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, Testing the PowerShell Editor 21 click the Run symbol in the toolbar (see Figure 1.15). The result will dis- play in the interactive Windows in the background. F 1. IRST S

WARNING Make sure the user account does not exist before running the WITH TEPS script. Otherwise the script will fail with the error “The account already exists.” W INDOWS P OWER S HELL

Figure 1.15 WPS IDE in script mode

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 con- text. That is, you can interactively access all script variables. To continue the script, press F8 or click the Continue icon in the toolbar. 22 Chapter 1 First Steps with Windows PowerShell

Figure 1.16 Script debugging with the WPS IDE

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 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 and is an interactive command-line shell. WPS is an optional feature on Windows Server 2008 and an add-on for Windows XP, Vista, and Server 2008. Commands in WPS are called commandlets. The PSCX extends WPS with additional commandlets. Summary 23

The PowerShellPlus is an alternative shell for WPS commands and an editor for WPS scripts. F 1.

In the next chapter, you learn much more about commandlets and IRST

pipelines. You also learn how to if you are seeking a command or S the available options for a commandlet. WITH TEPS W INDOWS P OWER S HELL INDEX

Symbols provider-independent, commandlets, 401 & (ampersand) operator, 382-383 configuring, 425-426 109 www.IT-Visions.de reading, 408-409 @ (at symbol) in hash extensions, 396-399 transferring, 424 tables, 107 directory services, 313 Active Directory = (equals sign), 109 file shares, 221 extensions ( ) (parentheses) in hash tables, 107 PSCX, 361 methods, 64 WMI Quest, 365 + (plus sign operator), collections, 146 www.IT-Visions.de, 54, 108 members, 142-144 362-364 “” (quotation marks) in objects, 137-138 group members parameters, 26 ACEs (access control assignments, 345 ; (semicolons) in entries), 225, 402 creating/filling, 345 commands, 90 adding to ACLs, 418-419 deleting, 346 * (star operator), 108, 356 contents, 402 listing, 343-344 | (vertical line) for deleting from ACLs, organizational units, pipelines, 43 421-423 346-347 reading, 410-411 schema A ACLs (access control lists), documentation, 338 access control entries. 225, 401-402 website, 450 See ACEs ACEs searching, 314 access control lists. adding, 418-419 indexed attributes, 354 See ACLs contents, 402 multivalued attributes, access rights, 403-406 deleting, 421-423 355-356 accessing reading, 410-411 result restrictions, 357 databases classes, 406 star operator, 356 commands, 383-385 control holders, 408 structure, 365-367 connections, 380-382 inheritance user accounts data readers, 386-388 hierarchy, 406 authentication, 341 DataSets. See ObjectSecurity, 406 creating, 339-340 DataSets reading ACLs, 408-409 deleting, 342 resources, 407 moving, 343

453 454 Index

passwords, 340 ADO.NET, 373 note properties, 67 renaming, 342 architecture, 374 properties, 65 user class, attributes, data providers, 375 property sets, 66 335-338 data source control script properties, 67 Active Directory Service elements, 377 AppendChild( ) Interfaces. See ADSI DataReader object, method, 246 Active Directory 376-378 AppendData right, 403 Management Objects DataSet object, 376-378 architecture (ADMO), 365 SQL Servers, listing Active Directory, AD Access Change/Break available, 376 365-367 in RC2 website, 449 ADSI (Active Directory ADO.NET, 374 ADAM (Active Directory Service Interfaces), ADSI, 316 Application 314 arrays, 105-106 Mode), 365 architecture, 316 associative, 106-108 add-content commandlet, deficiencies, 321-323 declaring, 105 429 directory services, defining, 105 binary files, 238 compared, 320 joining, 105 text files, writing, 236 DirectoryEntry class, listing, 105 add-directoryentry 318-319 multidimensional, 106 commandlet, integration, 316 at symbol (@) in hash 362, 429 object model, 318 tables, 107 add-history commandlet, property cache, 329 attributes, 213 429 search queries, 319 directory entries add-member commandlet, aliases, 29 reading, 328 429 creating, 30-31 writing, 329 Add-PSSnapin enumerating, 29 FileSystemAccessRule commandlet, properties, 68 objects, 410 175-176, 429 ambiguous commandlets, indexed, 354 add-user commandlet, 180 mailboxes, 304 362, 429 ampersand (&) operator, multivalued, 355-356 adding 109 Property, 318 ACEs to ACLs, 418-419 Analyzer, 164 services, 278 snap-ins, 175 analyzing pipeline user class (Active users to groups, 345 content, 59 Directory), 335-338 virtual web servers, alias properties, 68 authentication, 58, 341 308-311 code properties, 68 autostart applications, 263 AddPrinterConnection( ) ETS, 69-70 method get-member command- B–C (Win32_Printer let, 62, 66-69 binary files, 238 class), 287 get-pipelineinfo BIOS settings, 282 ADMO (Active Directory commandlet, 60 boot configuration Management methods, 64 settings, 282 Objects), 365 Index 455

calculated parameters, object analysis, 132 properties/methods, 27-28 static members, 130 142-144 calculations (pipelines), 76 ObjectSecurity, 406 queries, 147 calling methods, 64 security, 406 static class castrating objects, 73-74 control holders, 408 members, 144 Change( ) method inheritance System.Management (Win32_Service hierarchy, 406 object model, 135 class), 278 ObjectSecurity, 406 type indicators, 139 ChangePermission reading ACLs, 408-409 WPS support, 136 right, 403 resources, 407 XMLDocument, checking XML files, SmtpClient, 302 229, 244 242-243 String, 99 clear-content commandlet, classes TimeSpan, 103 429 attributes, 213 user (Active Directory), clear-item commandlet, CmdletInfo, 179 335-338 206, 429 COM WebClient, 300 clear-itemproperty COM objects, 135 Win32_Computersystem, commandlet, 429 creating instances, 133 281 clear-variable commandlet, existing instances, 134 Win32_Desktop, 315 429 DateTime, 102 Win32_LogicalDisk, clipboard, 200 DbProviderFactories, 382 207-210 close-dbconnection DirectoryEntries, 319 Win32_NetworkAdapter commandlet, 430 DirectoryEntry, 318-319 Configuration, 296 cmdlet development DriveInfo, 208 Win32_NTLogEvent, 291 guidelines FileInfo, 214 Win32_Operating website, 450 group policies, 367 System, 281 Cmdlet help website, 450 Hashtable, 107 Win32_PerfRawData, 292 CmdletInfo class, 179 IIsApplicationPool, 305 Win32_Product, 259 code properties, 68 IIsComputer, 305 Win32_Service, 277 COM classes IIsWebServer, 305 Win32_Share, 221 COM objects, 135 IIsWebService, 305 Win32_StartupCommand, instances IIsWebVirtualDir, 305 263 creating, 133 MailMessage, 302 Win32_Trustee, 226 existing, 134 ManagementDateTime- WMI, 135 command mode, 33, 154 Converter, 145 available, listing, 148 command-processing .NET, 129 collections, modes, 33 assemblies, loading, 131 accessing, 146 commandlets constructor instances, creating, 149 add-content, 429 parameters, 130 object access, 137-138 binary files, 238 enumerations, 132 object adapter, 139 text files, writing, 236 help, 38-40 object analysis, 140 add-directoryentry, instances, creating, 130 object filtering/ 362, 429 selecting, 146-147 456 Index

add-history, 429 export-csv, 239, 431 get-dbrow, 433 add-member, 429 expression integration, 33 get-dbtable, 433 add-pssnapin, 175, 429 extensions, 174-175, 181 get-dhcpserver, 433 add-user, 362, 429 external, 33-34 get-directory, 362 ambiguous, 180 file system administra- get-directorychildren, 433 case sensitivity, 29 tion, 205-206 get-directoryentry, clear-content, 429 foreach-object, 105, 362, 433 clear-item, 206, 429 235, 431 get-directoryvalue, clear-itemproperty, 429 format-byte, 431 362, 433 clear-variable, 429 format-custom, 431 get-disk, 206, 433 close-dbconnection, 430 format-hex, 431 get-domaincontroller, compare-object, 78, 430 format-list, 431 324, 433 convert-, 251 format-table, 431 get-eventlog, 290, 433 convert-path, 430 format-wide, 431 get-executionpolicy, 433 convert-, 249, 430 format-xml, 244, 431 get-exportedtype, 433 convertfrom-base64, 430 get-, 35 get-fileversioninfo, 433 convertfrom-secure- get-acl, 401, 431 get-foregroundwindow, string, 430 get-adobject, 314, 434 convertto-base64, 430 358, 431 get-hash, 434 convertto-html, 430 get-alias, 30, 432 get-help, 35, 434 convertto-macos9line- get-authenticode- get-history, 186, 434 ending, 430 signature, 432 get-host, 187, 434 convertto-securestring, get-bios, 432 get-item, 434 430 get-cdromdrive, 432 file properties, 213 convertto-unixline- get-childitem, 432 registry keys, 254 ending, 430 directory content, 210 get-itemproperty, convertto-windowsline- Filter parameter, 211 255, 434 ending, 430 include parameter, 211 get-ITVisions, 434 copy-item, 212, 254, 430 registry keys, 253 get-keyboard, 434 copy-itemproperty, 430 get-clipboard, 200, 432 get-location, 206, 434 data access, 396 get-command, 432 get-mailbox, 303 debugging parameters, get-computerinfo, 432 get-mailboxdatabase, 303 171 get-computername, 432 get-member, 62, definition, 25 get-content, 206, 432 66-68, 434 disable-mailbox, 304 binary files, 238 alias properties, 68 disconnect-- files, reading, 229, 235 code properties, 68 session, 430 get-credential, 58, 432 methods, 64 Exchange Server 2007, get-culture, 188, 432 note properties, 67 184-185 get-currentuser, 432 output, reducing, 69 export-alias, 431 get-datarow, 396 properties, 65 export-bitmap, 431 get-datatable, 396 property sets, 66 export-clixml, 248, 431 get-date, 102, 432 script properties, 67 export-console, 431 get-dbconnection, 432 get-memorydevice, 434 Index 457

get-metadata, 435 import-alias, 436 out-file, 55, 236, 438 get-mountpoint, 435 import-bitmap, 436 out-host, 51, 438 get-networkadapter, 435 import-clixml, 436 out-null, 438 get-PEheader, 435 import-csv, 240, 436 out-printer, 55, 287, 438 get-pfxcertificate, 435 import-dbcommand, 437 out-string, 438 get-pipelineinfo, 60, 435 invoke-dbcommand, 396 output, 49 get-pointingdevice, 435 invoke-expression, printing, 55 get-privilege, 435 109, 437 single values, 53-54 get-process, 11, 435 invoke-history, 437 standard, 51-53 processes, enumerat- invoke-item, 437 suppressing, 55 ing, 267-268 invoke-scalardb- text files, 55 processes, filtering, 268 command, 437 parameters, 26-27 get-process | out file, 55 join-path, 437 calculated, 27-28 get-process | out-printer, join-string, 102, 437 case sensitivity, 29 55 listing of, 35 filtering output, 28 get-processor, 435 measure-command, placeholders, 29 get-psdrive, 83, 206, 435 173, 437 quotation marks, 26 get-psprovider, 84, 435 measure-object, 76, 437 sequence, 27 get-pssnapin, 435 move-item, 206, ping-host, 296, 438 get-pssnapinhelp, 435 212, 437 pipelines get-random, 435 move-itemproperty, 437 calculations, 76 get-reparsepoint, 435 navigation, 84 castrating objects, get-service, 272, 435 new-alias, 30, 437 73-74 get-service i, 13 new-hardlink, 218, 437 classic commands, 46 get-shortpath, 436 new-item, 206, 437 comparing objects, 78 get-sounddevice, 436 registry keys, 254 content, analyzing. See get-storagegroup, 303 text files, creating, 236 pipelines, content get-tabexpansion, 436 new-itemproperty, analyzing get-tapedrive, 436 256, 437 creating, 43 get-terminalsession, 436 new-junction, 218, 437 filtering objects, 70-72 get-tracesource, 173, 436 new-mailboxdatabase, grouping objects, get-uiculture, 188, 436 303 74-75 get-unique, 436 new-object, 437 intermediate steps, get-usbcontroller, 436 new-psdrive, 438 viewing, 76 get-variable, 436 new-service, 278, 438 objects, 44-46 get-videocontroller, 436 new-shortcut, 217, 438 output, 49-55 get-wmiobject, 135, new-storagegroup, 303 Pipeline Processor, 144, 436 new-symlink, 220, 438 47-49 hardware information, new-timespan, 103, 438 ramifications, 78 284 new-variable, 438 sorting objects, 74 list parameter, 148 nouns, 29 user input, 56-58 group-object, 74, 436 out-clipboard, 438 placeholders, 29 help, 35, 38 out-default, 51, 438 pop-location, 438 458 Index

PSCX, 181-182, 214 set-date, 104, 440 test-path, 442 push-location, 438 set-dbtable, 440 test-xml, 243, 442 Quest, 183-184 set-directoryvalue, trace-command, 442 read-host, 56, 438 362, 440 tree-object, 78, 442 remove-directoryentry, set-distributiongroup, update-formatdata, 442 362, 438 304 update-typedata, 442 remove-item, 206, 212, set-executionpolicy, verbose parameter, 172 254, 438 119, 440 where-object, 70, 442 remove-itemproperty, set-filetime, 214, 440 write-bzip2, 442 257, 438 set-foregroundwindow, write-clipboard, 200, 442 remove-mountpoint, 439 440 write-debug, 442 remove-psdrive, 439 set-item, 206, 440 write-error, 53, 442 remove-pssnapin, 439 set-itemproperty, write-gzip, 442 remove-reparsepoint, 214, 440 write-host, 53, 442 439 set-location, 206, write-output, 443 remove-variable, 439 254, 441 write-progress, 443 rename-item, 206, set-privilege, 441 write-tar, 443 212, 439 set-psdebug, 173, 441 write-verbose, 443 rename-itemproperty, set-service, 278, 441 write-warn, 53 439 set-tracesource, 173, 441 write-warning, 443 resize-bitmap, 439 set-variable, 441 write-zip, 220, 443 resolve-assembly, set-volumelabel, commands 215, 439 210, 441 database access, 383-385 resolve-host, 299, 439 snap-ins, 179 history, 186-187 resolve-path, 439 sort-object, 74, 441 separating, 90 restart-service, 277, 439 split-path, 441 comments, 90 resume-service, 439 split-string, 101, 441 CommitChanges( ) SCVMM, 185 start-process, method, 329 select-object, 70, 73, 439 269-270, 441 compare-object select-string, 237, 439 start-service, 277, 441 commandlet, 78, 430 select-xml, 244-246, 439 start-sleep, 122, 441 comparing objects, 78 send-smtpmail, 302, 439 start-tabexpansion, 441 complex pipelines, 48-49 set-acl, 401, 440 start-transcript, 441 compression (files), set-alias, 30, 440 stop-process, 270, 441 220-221 set-authenticodesigna- stop-service, 277, 441 computers ture, 120, 440 stop-terminalsession, BIOS, 282 set-clipboard, 200, 440 441 boot configurations, 282 set-content, 206, 440 stop-transcript, 441 event logs, 290 binary files, 238 suspend-service, 442 entries, 290-291 text files, writing, 236 syntax, 26 names, 290 set-datarow, 396 test-assembly, 442 remote access, 291 set-datatable, 396 test-dbconnection, 396, 442 Index 459

hardware constant values creating information, viewing, (variables), 95 CSV files, 239 284-285 constructors (.NET directory entries, 332 printers, 286-289 classes), 130 Explorer links, 217 performance counters, control structures, 110-112 file shares, 223-224, 292-293 convert-html commandlet, 229-232 pinging, 295 251 groups product aviation convert-path commandlet, Active Directory, 345 settings, 282 430 policy links, 369-370 recovery settings, 283 convert-xml commandlet, hardlinks, 218 serial numbers, 282 249, 430 junction points, 218 settings, viewing, convertfrom-base64 mailboxes, 303 281-283 commandlet, 430 organizational units, software versions, 282 convertfrom-securestring 346-347 configuring commandlet, 430 public folders, 305 ACLs, 425-426 convertto-base64 registry keys, 254-257 date and time, 104 commandlet, 430 symbolic links, 220 files convertto-html user accounts, 339-340 date and time, 214 commandlet, 430 websites from CSV files, share permissions, convertto-macos9lineend- 309-311 225-228 ing commandlet, 430 CSV files, 239 networking, 296-298 convertto-securestring creating, 239 confirm parameter, 171 commandlet, 430 exporting, 239 connections convertto-unixlineending importing, 240 databases, 380-382 commandlet, 430 websites, creating, printers, 287 convertto-windowslineend- 309-311 consoles ing commandlet, 430 customizing interactive mode, 11 ConvertToDateTime( ) file properties, 214 WPS, 151 method, 145 service configuration, command history, copy-item commandlet, 278-279 186-187 212, 254,430 strings, 100 command mode, 154 copy-itemproperty XML documents, 246 functions, 152 commandlet, 430 interpreter mode, 154 copying D PowerTab, 156 files/folders, 212 data snap-ins, loading, registry keys, 254 adapters, 391 175-176 CreateDirectories providers, 375 tab completion, 153 right, 403 readers, 386-388 Vista user account CreateElement( ) types, 92 control, 155 method, 246 listing of, 92 CreateFiles right, 404 registry, 257 variables, 91-93 460 Index

databases remote computers, 104 dialog boxes access setting, 104 authentication, 58 commands, 383-385 WMI date format con- user input, 57 connections, 380-382 versions, 145 digital signatures, 120-121 data readers, 386-388 DateTime class, 102 directory content DataSets. See DbProviderFactories files/folders operations, DataSets class, 382 212-213 provider-independent, deactivating mailboxes, 304 viewing, 210-212 382-383 debug parameter, 171 directory services www.IT-Visions.de debugging access, 313 extensions, 396-399 commandlet parameters ADSI ADO.NET, 373 for, 171 compared, 320 architecture, 374 PowerShellPlus, 21 deficiencies, 321-323 data providers, 375 PowerShellPlus paths, 323-325 data source control Editor, 163 programming, 325 elements, 377 step-by-step, 173 ADSI property DataReader object, verbose parameter, 172 cache, 329 376-378 declaring binding meta objects DataSet object, arrays, 105 to directory entries, 376-378 variables, 91 325-326 enumerating data default naming container objects, 331 providers, 375 context, 324 directory entries, 332 SQL Servers, listing Delete right, 404 directory entry available, 376 DeleteSubdirectoriesAnd- attributes, 328-329 example, 379 Files right, 404 directory entry exis- mailboxes, 303 DeleteTree( ) method, 342 tence, checking, 327 DataReader object, deleting impersonation, 327 376-378 ACEs to ACLs, 421-423 object properties, 330 DataSets, 389 directory entries, 332 www.IT-Visions.de com- data adapter, 391 files/folders, 212 mandlets, 362-364 object model, links, DirectoryEntries class, 319 376-378, 390 370-372 DirectoryEntry class, provider-independent junction points, 219 318-319 example, 394-395 print jobs, 288 disable-mailbox provider-specific registry keys, 254, 257 commandlet, 304 example, 391-393 text file content, 236 disconnect-terminalsession XML exports/ users commandlet, 430 imports, 395 Active Directory, 342 DLL registration, 175 DataTable objects, 390 groups, 346 DNs (distinguished date and time, 102-103, 145 virtual web servers, 311 names), 323 files, 214 dependent services, periods of time, 103 274-276 Index 461 documents E management shell, binary files, 238 e-mail, sending, 302 184-185 CSV files, 239 ending processes, 270 public folder creating, 239 enumerating management, 305 exporting, 239 aliases, 29 scripts website, 451 importing, 240 data providers, 375 storage groups, 303 HTML, 251 file shares, 223 executable files text files group policies, 367-369 PE header information, content, deleting, 236 .NET classes, 132 215 reading, 235-236 processes, 267-268 PSCX commandlets, 214 searching, 237 services, 272-273 viewing, 215 writing to, 236-237 environment variables, ExecuteFile right, 404 XML, 241 viewing, 283 execution policies, 119 checking, 242-243 equals sign (=), 109 execution time, converting to XHTML ErrorAction parameter, measuring, 173 files, 249 125-127 Exists( ) method, 327 customizing, 246 errors (scripts), 122 Explorer links, 216-217 formatting, 244 creating, 128 export-alias commandlet, object pipeline, 248 handling, 125-127 431 reading, 241 history, 128 export-bitmap searching with standard reactions, 127 commandlet, 431 XPath, 244 trap blocks, 128 export-clixml commandlet, domain controllers (Active trapping example, 248, 431 Directory), 366-367 123-125 export-console domains (Active ETS (Extended Type commandlet, 431 Directory), 366 System), 44 export-csv commandlet, dot sourcing, 118 pipeline content, 239, 431 downloading analyzing, 69-70 exporting PSCX, 17 website, 450 CSV files, 239 RSS feeds, 301 event logs, 290 DataSets, 395 WPS, 8 entries, 290-291 expressions, 32-33 DownloadString( ) filtering, 14 Extended Reflection, 44 method, 300 names, 290 Extended Type System. DriveInfo class, 208 remote access, 291 See ETS drives Exchange Management extensions defining, 87-88, 255 Shell website, 451 commandlets, free space, viewing, Exchange Server 2007, 302 174-175, 181 208-210 basic operations, 302 PSCX listing all, 206-207 databases, listing, 303 Active Directory, 361 names, 210 functionality, testing, 303 commandlets, 181-182 network, 210 mailboxes, 303-304 LDAP filters, 358 providers, 83-84 462 Index

Quest, 365 links, 216 text www.IT-Visions.de, 183 Explorer, 216-217 content, deleting, 236 Active Directory, hardlinks, 217-218 reading, 235-236 362-364 junction points, searching, 237 database access, 218-219 writing to, 236-237 396-399 symbolic, 220 XML, 241 external commandlets, FileInfo class, 214 checking, 242-243 33-34 files converting to XHTML binary, 238 files, 249 F compression, 220-221 customizing, 246 file system administration copying, 212 DataSet access rights, 403-406 CSV, 239 exports/imports, 395 commandlets, 205-206 creating, 239 formatting, 244 directory content, exporting, 239 object pipeline, 248 viewing, 210-212 importing, 240 reading, 241 drives websites, creating, searching with free space, displaying, 309-311 XPath, 244 208-210 deleting, 212 FileSystemAccessRule listing all, 206-207 executable objects, 410 names, 210 PE header filling groups, 345 network, 210 information, 215 Filter parameter executable files PSCX commandlets, (get-childitem PE header 214 commandlet), 211 information, 215 viewing, 215 filtering PSCX commandlets, HTML, 251 event logs, 14 214 moving, 212 LDAP queries, 358 viewing, 215 names, 34 objects, 70-72 file compression, properties conditions, 70 220-221 customizing, 214 heterogeneous file properties date/time information, pipeline content, 72 customizing, 214 214 parameter output, 28 date/time information, viewing, 213 processes, 268 214 renaming, 212 RSS feeds, 301 viewing, 213 retrieving from HTTP WMI objects, 146-147 file shares servers, 300-301 flags (parameters), 420 accessing, 221 shares folders creating, 223-224 accessing, 221 copying, 212 enumerating, 223 creating, 223-224 deleting, 212 mass creation, 229-232 enumerating, 223 moving, 212 permissions, 225-228 mass creation, 229-232 public, 305 files/folders operations, permissions, 225-228 renaming, 212 212-213 Index 463

foreach-object commandlet, get-clipboard commandlet, get-disk commandlet, 105, 235, 431 200, 432 206, 433 forests (Active Directory), get-command get-domaincontroller 366 commandlet, 432 commandlet, format-byte commandlet, get-commandlet, 35 324, 433 431 get-computerinfo get-eventlog commandlet, format-custom commandlet, 432 290, 433 commandlet, 431 get-computername get-executionpolicy format-hex commandlet, commandlet, 432 commandlet, 433 431 get-content commandlet, get-exportedtype format-list commandlet, 206, 432 commandlet, 431 binary files, 238 215, 433 format-table commandlet, files, reading, 229, 235 get-fileversioninfo 431 get-credential commandlet, format-wide commandlet, commandlet, 58, 432 215, 433 431 get-culture commandlet, get-foregroundwindow format-xml commandlet, 188, 432 commandlet, 434 244, 431 get-currentuser get-hash commandlet, 434 formatting XML files, 244 commandlet, 432 get-help commandlet, free space (drives), get-datarow commandlet, 35, 434 208-210 396 get-history commandlet, FullControl right, 404 get-datatable commandlet, 186, 434 396 get-host commandlet, G get-date commandlet, 187, 434 get-acl commandlet, 102, 432 get-item commandlet, 434 401, 431 get-dbconnection file properties, 213 get-adobject commandlet, commandlet, 432 registry keys, 254 314, 358, 431 get-dbrow commandlet, get-itemproperty get-alias commandlet, 433 commandlet, 30, 432 get-dbtable commandlet, 255, 434 get-authenticodesignature 433 get-ITVisions commandlet, commandlet, 432 get-dhcpserver 434 get-bios commandlet, 432 commandlet, 433 get-keyboard commandlet, get-cdromdrive get-directorychildren 434 commandlet, 432 commandlet, get-location commandlet, get-childitem commandlet, 362, 433 206, 434 432 get-directoryentry get-mailbox commandlet, directory content, 210 commandlet, 303 Filter parameter, 211 362, 433 get-mailboxdatabase include parameter, 211 get-directoryvalue commandlet, 303 registry keys, 253 commandlet, 362, 433 464 Index

get-member commandlet, get-pssnapinhelp GetAccessRules( ) 62, 66-68, 434 commandlet, 435 method, 411 alias properties, 68 get-random commandlet, GetDrives( ) method, 206 code properties, 68 435 GetFactoryClasses( ) methods, 64 get-reparsepoint method, 375 note properties, 67 commandlet, 435 GetOwner( ) method, 417 output, reducing, 69 get-service commandlet, GetType( ) method, 93 properties, 65 272, 435 GPMC (Group Policy property sets, 66 get-service i commandlet, Management script properties, 67 13 Console), 367, 450 get-memorydevice get-shortpath commandlet, GPMGMT component, commandlet, 434 436 367 get-metadata commandlet, get-sounddevice graphical user interfaces, 435 commandlet, 436 196 get-mountpoint get-storagegroup clipboard, 200 commandlet, 435 commandlet, 303 input window, 196-198 get-networkadapter get-tabexpansion objects, displaying, commandlet, 435 commandlet, 436 198-200 get-peheader commandlet, get-tapedrive commandlet, group-object commandlet, 215, 435 436 74, 436 get-pfxcertificate get-terminalsession Group Policy Management commandlet, 435 commandlet, 436 Console (GPMC), get-pipelineinfo get-tracesource 367, 450 commandlet, 60, 435 commandlet, grouping objects, 74-75 get-pointingdevice 173, 436 groups commandlet, 435 get-uiculture commandlet, Active Directory get-privilege commandlet, 188, 436 creating/filling, 345 435 get-unique commandlet, deleting users, 346 get-process commandlet, 436 members, 343-345 11, 267-268, 435 get-usbcontroller policies, 367 get-process | out file commandlet, 436 classes, 367 commandlet, 55 get-variable commandlet, enumerating, 367, 369 get-process | out-printer 436 links, 369-372 commandlet, 55 get-videocontroller WMI management, get-processor commandlet, commandlet, 436 314-315 435 get-wmiobject get-psdrive commandlet, commandlet, 135, H 83, 206, 435 144, 436 handling script errors, get-psprovider hardware information, 125-127 commandlet, 84, 435 284 hardlinks, 217-218 get-pssnapin commandlet, list parameter, 148 435 Index 465

hardware IIsWebVirtualDir .NET classes, 161 information, viewing, class, 305 path names, 160 284-285 import-alias commandlet, variables, 162 printers 436 PrimalScript connections, 287 import-bitmap class names, 169 listing all, 286 commandlet, 436 commandlets, 168 print jobs, 287-289 import-clixml parameters, 168 status, 286 commandlet, 436 interactive mode, 11, 14 hash tables, 106-108 import-csv commandlet, console window, 11 Hashtable class, 107 240, 436 event logs, filtering, 14 help import-dbcommand IDE, 156 commandlets, 35, 38 commandlet, 437 installed services, get-commandlet, 35 importing viewing, 13 .NET classes, 38-40 CSV files, 240 pipeline features, 13 PSL, 90 DataSets, 395 running processes, tool, 169 include parameter viewing, 11 Help Editor website, 449 (get-childitem tab completion, 13 heterogeneous pipeline commandlet), 211 interfaces content, 72 indexed attributes ADSI hexadecimal numbers, 96 (Active Directory architecture, 316 history searches), 354 deficiencies, 321-323 commands, 186-187 input boxes, 56 directory services, WPS, 4-5 input windows, 196-198 compared, 320 host information, 187-188 InputBox( ) method, 56 DirectoryEntry class, HTML files, 251 Install( ) method 318-319 (Win32_Product( ) integration, 316 I class), 263 object model, 318 IADs interface, 317 installed services, property cache, 329 IDE, 156-157 viewing, 13 search queries, 319 IEnumerable interface, 319 installing graphical user IIS (Internet Information PowerShellPlus, 19 interfaces, 196 Services), 305 printers, 287 clipboard, 200 classes, 305 PSCX, 17 input window, 196-198 virtual web servers services, 278 objects, displaying, adding, 308-311 software, 263 198-200 deleting, 311 WPS, 8-10 IADs, 317 listing, 307 installutil.exe, 175 IEnumerable, 319 IIsApplicationPool IntelliSense intermediate steps class, 305 PowerShellPlus (pipelines), IIsComputer class, 305 commandlet viewing, 76 IIsWebServer class, 305 names, 159 Internet Information IIsWebService class, 305 commandlet Services. See IIS parameters, 160 466 Index

interpreter mode (WPS search example, 352 Active Directory user console), 154 search filters accounts inventory (software) website, 450 authentication, 341 script, 260-261 syntax, 349-350 creating, 340 searching, 260 user login name deleting, 342 viewing, 259 searches, 353-354 moving, 343 invoke-dbcommand links renaming, 342 commandlet, 396 file system, 216 binary files, 238 invoke-expression Explorer, 216-217 COM classes commandlet, hardlinks, 217-218 existing instances, 134 109, 437 junction points, instantiating, 133 invoke-history 218-219 database access commandlet, 437 symbolic, 220 data readers, 387-388 invoke-item commandlet, group policies provider-independent 437 creating, 369-370 command objects, invoke-scalardbcommand deleting, 370-372 384 commandlet, 437 parameter flags, 420 www.IT-Visions.de list parameter extensions, 398-399 J–K get-eventlog database connections Join( ) method, 102 commandlet, 290 Microsoft Access, 381 join-path commandlet, 437 get-wmiobject Microsoft SQL Server, join-string commandlet, commandlet, 148 381-382 102, 437 ListDirectory right, 404 Microsoft SQL Server joining listings Express, 382 arrays, 105 ACEs provider-independent, hash tables, 108 adding, 419 383 strings, 102 deleting, 422-423 DataSets junction points, 218-219 details, 411 provider-independent keys (registry) ACL transfers, 424-426 example, 394-395 copying, 254 Active Directory provider-specific creating, 254 domain controllers, 366 example, 392-393 deleting, 254 domains/forests, 366 dialog box user input entries, 255-257 search result example, 57 hierarchy script, 115-117 restrictions, 357 directory container reading, 253-254 user accounts, objects, 331 Kill( ) method (Process passwords, 341 directory entries, 332 class), 270 Active Directory groups directory objects creating, 345 customizing, 330 L deleting members, 346 fetching, 328 LDAP queries listing members, 344 properties, 331 example, 350 member assignments, executing, 351 346 filters, 358 Index 467

directory service protocol entries, user input, 56 operations via fetching, 291 user profiles www.IT-Visions.de registry example, 258 PSCX, 190-195 commandlets, scripts script, 188 363-364 dot sourcing, 118 variable resolution downloading files via error testing example, within a string, 99 HTTP, 300 123-125 virtual web servers downloading/filtering registry key hierarchy, information, RSS feeds, 301 115-117 viewing, 308 drive free space, viewing services waiting for process DriveInfo class, 208 configuration, ending, 271 Win32_LogicalDisk customizing, 278 websites, creating from class, 209-210 enumerating, 272 CSV files, 309-311 drive names, 210 SIDs WMI e-mail, sending, 302 displaying, 414 classes, instantiating, executable files, SDDL names, 416 149 viewing, 215 well-known, 415 date format files software conversions, 145 date and time, installations, testing, XML files configuring, 214 265-266 customizing, 247 share permissions, installing, 264 fetching, 242 creating, 226-228 inventory script, loading shares, creating, 224, 260-261 assemblies, .NET 230-232 inventory solution with classes, 131 formatted output, 55 WPS, 8 snap-ins, WPS console, get-wmiobject inventory solution with 175-176 commandlet, 144 WSH, 5-7 locking variables, 95 group policies searching inventory, logical operators, 72 enumerating, 368-369 260 links, 370-372 uninstalling, 264 M input windows, 196-198 strings mailboxes (Exchange LDAP customizing, 100 Server) searches, executing, 352 joining, 102 attributes, 304 user login name splitting, 101 creating, 303 search, 354 subroutines, 112 deactivating, 304 networks, configuring, system owners, listing, 303 297-298 reading, 418 managing, 303-304 objects, displaying, text files moving, 304 198-200 reading, 235 MailMessage class, 302 organizational units, writing to, 236 ManagementBaseObject creating, 347 user accounts, class, 135 print jobs, canceling, 288 creating, 14 468 Index

ManagementClass RemoveAccessRule( ), .NET class, 135 421 3.0 Redistributable ManagementDateTime- SelectNodes( ), 229, 244 package website, 10 Converter class, 145 SelectSingleNode( ), 244 classes, 129 ManagementObject SetInfo( ), 317 assemblies, loading, 131 class, 135 Slit( ), 101 constructor mass creation, file shares, String class, 99 parameters, 130 229-232 Subtract( ), 103 enumerations, 132 measure-command ToDateTime( ), 145 help, 38-40 commandlet, ToString( ), 60 instances, creating, 130 173, 437 Uninstall( ), 264 library documentation measure-object WM classes, 142, 144 for FileSystemRights commandlet, 76, 437 Modify right, 404 enumeration measuring execution move-item commandlet, website, 450 time, 173 206, 212, 437 object analysis, 132 methods, 64 move-itemproperty static members, 130 AddPrinterConnection( ), commandlet, 437 Community website, 449 287 moving regular expressions AppendChild( ), 246 files/folders, 212 website, 450 calling, 64 mailboxes, 304 tools and software Change( ), 278 user accounts, 343 components refer- CommitChanges( ), 329 multidimensional ence website, 449 ConvertToDateTime( ), arrays, 106 NetCmdlets from 145 multivalued attributes nsoftware website, CreateElement( ), 246 (Active Directory 450 DeleteTree( ), 342 searches), 355-356 networking DownloadString( ), 300 configuring, 296-298 Exists( ), 327 N drives, 210 GetAccessRules( ), 411 name resolution, 299 e-mail, sending, 302 GetDrives( ), 206 names Exchange Server 2007, GetFactoryClasses( ), 375 drives, 210 302 GetOwner( ), 417 event logs, 290 basic operations, 302 GetType( ), 93 files/folders, 212 databases, listing, 303 InputBox( ), 56 SDDL, 416-417 functionality, Install( ), 263 navigating testing, 303 Join( ), 102 Active Directory, 361 mailboxes, 303-304 Kill( ), 270 commandlets, 84 public folder object pipelines, 45-46 drives, defining, 87-88 management, 305 PurgeAccessRules( ), 421 paths, 85-86 storage groups, 303 RefreshCache( ), 329 registry, 83-84 file retrieval from HTTP servers, 300-301 Index 469

IIS, 305 numbers, 96-98 out-file commandlet, 55, classes, 305 assigning to untyped 236, 438 virtual web servers, variables, 96 out-host commandlet, 307-311 hexadecimal, 96 51, 438 name resolution, 299 random, 98 out-null commandlet, 438 pinging computers, 295 out-printer commandlet, new-alias commandlet, O 55, 287, 438 30, 437 object model (DataSets), out-string commandlet, new-hardlink commandlet, 390 438 218, 437 objects output, 49 new-item commandlet, castrating, 73-74 get-member 206, 437 comparing, 78 commandlet registry keys, 254 displaying, 198-200 alias properties, 68 text files, creating, 236 filtering, 70-72 code properties, 68 new-itemproperty conditions, 70 methods, 64 commandlet, heterogeneous note properties, 67 256, 437 pipeline content, 72 properties, 65 new-junction commandlet, grouping, 74-75 property sets, 66 218, 437 .NET classes, 132 reducing, 69 new-mailboxdatabase orientation, pipelining, script properties, 67 commandlet, 303 44 mixing literals and new-object commandlet, pipelines, 44 variables, 54 437 HTML files, 251 printing, 55 new-psdrive commandlet, methods, 45-46 single values, 53-54 438 parameters, 46 standard, 51-53 new-service commandlet, XML documents, 248 pagewise, 51 278, 438 sorting, 74 restricting, 52 new-shortcut commandlet, WMI suppressing, 55 217, 438 accessing, 137-138 text files, 55 new-storagegroup adapter, 139 commandlet, 303 analysis, 140 P new-symlink commandlet, filtering/selecting, p parameter (out-host 220, 438 146-147 commandlet), 51 new-timespan ObjectSecurity class, 406 pagewise output, 51 commandlet, operators, 72, 108-109 parameters, 26-27 103, 438 organizational units, calculated, 27-28 new-variable commandlet, creating, 346-347 case sensitivity, 29 438 out-clipboard debugging, 171 nonterminating errors, 122 commandlet, 438 ErrorAction, 125-127 note properties, 67 out-default commandlet, Filter, 211 nouns (commandlets), 29 51, 438 filtering output, 28 470 Index

flags, linking, 420 ETS, 69-70 placeholders, 29 include, 211 get-member plus sign (+) operator, LDAP queries, 349 commandlet, 62, 54, 108 list 66-69 policies get-eventlog get-pipelineinfo execution, 119 commandlet, 290 commandlet, 60 group, 367 get-wmiobject methods, 64 classes, 367 commandlet, 148 note properties, 67 creating links, 369-370 .NET class constructors, properties, 65 deleting links, 370-372 130 property sets, 66 enumerating, 367-369 object pipelines, 46 script properties, 67 pop-location commandlet, p, 51 creating, 43 438 placeholders, 29 features, 13 PowerShell quotation marks, 26 heterogeneous Analyzer, 164 sequence, 27 content, 72 Community Extensions. start-process intermediate steps, view- See PSCX commandlet, 270 ing, 76 documentation parentheses ( ) in objects, 44 website, 449 methods, 64 castrating, 73-74 download website, 449 passwords (user comparing, 78 Help, 169 accounts), 340 filtering objects, 70-72 IDE, 156-157 paths, 85-86, 323-325 grouping, 74-75 Pipeline Processor, pausing HTML files, 251 47-49 print jobs, 288 methods, 45-46 remoting website, 449 scripts, 122 orientation, 44 Script Language. performance counters, parameters, 46 See PSL 292-293 sorting, 74 PowerShell periods of time, 103 XML, 248 2.0, 445-447 permissions (file shares), output, 49 PowerShellPlus, 19, 158 225-228 printing, 55 debugging, 21, 163 ping-host commandlet, single values, 53-54 functions, 158 296, 438 standard, 51-53 installing, 19 pinging computers, 295 suppressing, 55 IntelliSense Pipeline Processor, 47-49 text files, 55 commandlets, 159-160 pipelines Pipeline Processor, .NET classes, 161 | (vertical line), 43 47-49 path names, 160 calculations, 76 ramifications, 78 variables, 162 classic commands, 46 user input, 56 PrimalScript, complex, 48-49 authentication dialog compared, 166 content, analyzing, 59 boxes, 58 testing, 20 alias properties, 68 dialog boxes, 57 variables, viewing all, 164 code properties, 68 input box, 56 website, 19 Index 471

PowerShellPlus Editor, 22 deleting, 332 PSL (PowerShell Script PowerTab, 156 existence, checking, 327 Language), 89 predefined variables, 93 impersonation, 327 arrays, 105-106 PrimalScript, 165 object properties, 330 associative, 106-108 IntelliSense properties, 65 declaring, 105 class names, 169 alias, 68 defining, 105 commandlets, 168 code, 68 joining, 105 parameters, 168 directory objects, 330 listing, 105 PowerShellPlus, files multidimensional, 106 compared, 166 customizing, 214 command separation, 90 website, 166 date/time information, comments, 90 WPS script output, 167 214 control structures, printers viewing, 213 110-112 connections, 287 note, 67 data types, 92 jobs, 287-289 PSSnapIn, 179 date and time, 102-103 listing all, 286 script, 67 periods of time, 103 output, 55 WMI classes, 142-144 remote computers, 104 print jobs, 287-289 Property attribute setting, 104 status, 286 (DirectoryEntry hash tables, 106-108 priority parameter class), 318 accessing, 107 (start-process property sets, 66 defining, 107 commandlet), 270 Prosser, Karl, 164 joining, 108 processes, 267 provider factories, 384 help, 90 ending, 270 providers, 83-84 numbers, 96-98 enumerating, 267-268 independent data access, assigning to untyped filtering, 268 382-383 variables, 96 running, 11 listing of, 84 hexadecimal, 96 starting, 269-270 viewing, 84 random, 98 waiting for ending, 271 PSCX (PowerShell operators, 108-109 product activation Community strings, 99 settings, 282 Extensions), 17, 181 customizing, 100 profiles, 189-195 Active Directory joining, 102 programming directory navigation, 361 splitting, 101 services, 325 commandlets, 181-182 variables, 91 ADSI property cache, 329 downloading, 17 constant values, 95 binding meta objects to executable files data types, 91-93 directory entries, commandlets, 214 declaring, 91 325-326 installing, 17 example, 94 container objects, 331 LDAP filters, 358 predefined, 93 directory entries testing, 18 resolution, 95 attributes, 328-329 website, 181, 449 creating, 332 472 Index

PSSnapIn property reading remove-mountpoint (CmdletInfo ACEs, 410-411 commandlet, 439 class), 179 ACLs, 408-409 remove-psdrive public folders, binary files, 238 commandlet, 439 managing, 305 directory entry remove-pssnapin PurgeAccessRules( ) attributes, 328 commandlet, 439 method, 421 registry keys, 253-255 remove-reparsepoint push-location system owners, 417 commandlet, 439 commandlet, 438 text files, 235-236 remove-variable XML files, 241 commandlet, 439 Q ReadPermissions right, 405 RemoveAccessRule( ) queries recovery settings, 283 method, 421 LDAP reflection mechanism, 44 rename-item commandlet, example, 350 RefreshCache( ) 206, 212, 439 executing, 351 method, 329 rename-itemproperty filters, 358 registry, 253 commandlet, 439 search example, 352 data types, 257 renaming syntax, 349-350 drives, defining, 255 files/folders, 212 user login name example, 257-258 users, 342 searches, 353-354 keys resize-bitmap WQL, 147 copying, 254 commandlet, 439 Quest creating, 254 resolution (variables), 95 extensions (Active deleting, 254 resolve-assembly Directory), 365 entries, 255-257 commandlet, Management Shell for hierarchy script, 215, 439 Active Directory, 115-117 resolve-host commandlet, 183-184 reading, 253-254 299, 439 quotation marks (“ ”) in navigating, 81 resolve-path commandlet, parameters, 26 commandlets, 84 439 drives, 83-84 resources (security providers, 83-84 classes), 407 ramifications (pipelines), 78 regular expressions, 71 restart-service random numbers, 98 relational operators, 72 commandlet, Read right, 404 remote computers, date 277, 439 read-host commandlet, and time, 104 restricting output, 52 56, 438 remove-directoryentry resume-service ReadAndExecute right, 404 commandlet, commandlet, 439 ReadAttributes right, 404 362, 438 retrieving files from HTTP ReadData right, 405 remove-item commandlet, servers, 300-301 ReadExtendedAttributes 206, 212, 254, 438 rights (access), 403-406 right, 405 remove-itemproperty RSS feeds, 301 commandlet, running processes, 257, 438 viewing, 11 Index 473

S SDK website, 450 (SDs), schemas (Active SDs (security descriptors), 225, 402 Directory), 338 225, 402 security identifiers. script mode, 14-15, 156 search queries (ADSI), 319 See SIDs scripts searching select-object commandlet, DataSet providers Active Directory, 314 70, 73, 439 independent example, indexed attributes, 354 select-string commandlet, 394-395 multivalued attributes, 237, 439 specific example, 355-356 select-xml commandlet, 391-393 result restrictions, 357 244-246, 439 debugging, 21 star operator, 356 selecting WMI digital signatures, software inventory, 260 objects, 146 120-121 text files, 237 SelectNodes( ) method dot sourcing, 118 XML files, 244 (XMLDocument errors, 122 security, 402 class), 229, 244 creating, 128 access rights, 403-406 SelectSingleNode( ) handling, 125-127 ACLs, 402 method history, 128 ACEs, 402 (XmlDocument standard reactions, 127 adding ACEs, 418-419 class), 244 trap blocks, 128 configuring, 425-426 semicolons (;) in trapping example, deleting ACEs, commands, 90 123-125 421-423 send-smtpmail Exchange Server scripts reading ACEs, commandlet, website, 451 410-411 302, 439 pausing, 122 transferring, 424 sending e-mail, 302 properties, 67 classes, 406 sequence (parameters), 27 registry key hierarchy, control holders, 408 serial numbers 115-117 inheritance (computers), 282 security, 118-119 hierarchy, 406 servers software inventory, ObjectSecurity, 406 HTTP, 300-301 260-261 reading ACLs, 408-409 SQL, 376 starting, 117 resources, 407 virtual web servers user accounts, descriptors (SDs), adding, 308-311 creating, 14 225, 402 deleting, 311 SCVMM (System Center owners, reading, 417 listing, 307 Virtual Machine scripts, 118-119 services Manager), 185 SIDs attributes, 278 SDDL (Security Descriptor displaying, 414 configuration, Definition SDDL names, 416-417 customizing, 278-279 Language), 416 well-known, 414-416 dependent, 274-276 ACLs, configuring, user accounts, 402 directory, 325 425-426 Security Descriptor access, 313 names, 416-417 Definition Language. ADSI. See ADSI See SDDL 474 Index

binding meta objects set-distributiongroup SmtpClient class, 302 to directory entries, commandlet, 304 snap-ins 325-326 set-executionpolicy adding, 175 container objects, 331 commandlet, commandlets, 179 directory entries, 332 119, 440 listing, 178 directory entry set-filetime commandlet, loading in WPS console, attributes, 328-329 214, 440 175-176 directory entry exis- set-foregroundwindow Snover, Jeffrey, 117 tence, checking, 327 commandlet, 440 software, 259 impersonation, 327 set-item commandlet, autostart, 263 object properties, 330 206, 440 installed list of, 262 paths, 323-325 set-itemproperty com- installing, 263 www.IT-Visions.de mandlet, 214, 440 inventory commandlets, set-location commandlet, script, 260-261 362-364 206, 254, 441 searching, 260 enumerating, 272-273 set-privilege commandlet, solution with WPS, 8 installed, viewing, 13 441 solution with WSH, installing, 278 set-psdebug commandlet, 5-7 starting, 276-277 173, 441 viewing, 259 stopping, 277 set-service commandlet, not installed with set-acl commandlet, 278, 441 , 401, 440 set-tracesource 262 set-alias commandlet, commandlet, uninstalling, 264 30, 440 173, 441 versions, viewing, 282 set-authenticodesignature set-variable commandlet, sort-object commandlet, commandlet, 441 74, 441 120, 440 set-volumelabel sorting objects, 74 set-clipboard commandlet, commandlet, Split( ) method, 101 200, 440 210, 441 split-path commandlet, set-content commandlet, SetInfo( ) method, 317 441 206, 440 settings (computers), split-string commandlet, binary files, 238 281-283 101, 441 text files, writing, 236 SharePoint Provider splitting strings, 101 set-datarow commandlet, website, 449 SQL Servers, listing avail- 396 SIDs (security able, 376 set-datatable commandlet, identifiers), 402 standard output, 51-53 396 displaying, 414 pagewise, 51 set-date commandlet, SDDL names, 416-417 restricting, 52 104, 440 well-known, 414-416 star operator (*), 108, 356 set-dbtable commandlet, signing scripts, 120-121 start-process commandlet, 440 single value output, 53-54 269-270, 441 set-directoryvalue SMTP (Simple Mail Transfer start-service commandlet, commandlet, Protocol), 302 277, 441 362, 440 Index 475

start-sleep commandlet, logical operators, 72 time and date, 102-103 122, 441 regular expressions, 71 periods of time, 103 start-tabexpansion relational operators, 72 remote computers, 104 commandlet, 441 System Center Virtual setting, 104 start-transcript Machine Manager TimeSpan class, 103 commandlet, 441 (SCVMM), 185 ToDateTime( ) starting system information, method, 145 processes, 269-270 187-188 ToString( ) method, 60 scripts, 117 system owners, trace-command services, 276-277 reading, 417 commandlet, 442 static members System.Management tracing, 173 .NET classes, 130 object model, 135 transferring ACLs, 424 WMI classes, 144 System.Management Traverse right, 405 step-by-step debugging, namespace tree-object commandlet, 173 documentation 78, 442 stop-process commandlet, website, 450 trial and error website, 451 270, 441 type indicators (WMI stop-service commandlet, T classes), 139 277, 441 tab completion, 13, 153 stop-terminalsession TakeOwnership right, 405 U commandlet, 441 targets (junction Uninstall( ) method stop-transcript points), 219 (Win32_Product commandlet, 441 terminating errors, 122 class), 264 stopping services, 277 test-assembly commandlet, uninstalling storage limitations (public 214, 442 software, 264 folders), 305 test-dbconnection WPS, 10 String class, 99 commandlet, update-formatdata strings, 99 396, 442 commandlet, 442 customizing, 100 test-path commandlet, 442 update-typedata joining, 102 test-xml commandlet, commandlet, 442 representation, 60 243, 442 user accounts splitting, 101 testing Active Directory, subroutines, 112 Exchange Server 2007 335-338 Subtract( ) method, 103 functionality, 303 authentication, 341 suspend-service PowerShellPlus, 20-22 creating, 339-340 commandlet, 442 PSCX, 18 deleting, 342 symbolic links, 220 text files moving, 343 Synchronize right, 405 content, deleting, 236 passwords, 340 syntax reading, 235-236 renaming, 342 commandlets, 26 searching, 237 creating, 14 LDAP queries, 349-350 writing to, 236-237 security, 402 476 Index

user administration drive free space (file Exchange Server Active Directory system), 208, 210 scripts, 451 authentication, 341 drives list, 206-207 Group Policy deleting users, 342 environment Management moving users, 343 variables, 283 Console with Service renaming users, 342 executable files, 215 Pack 1, 450 user accounts, 339-340 file properties, 213 Help Editor, 449 user class attributes, hardware information, LDAP search filters, 450 335-338 284-285 .NET Framework WMI, 314-315 installed services, 13 3.0 Redistributable users objects, 198-200 package, 10 adding to groups, 345 pipeline intermediate class library deleting from steps, 76 documentation for groups, 346 providers, 84 FileSystemRights input, 56 running processes, 11 enumeration, 450 authentication dialog SIDs, 414 Community, 449 boxes, 58 software inventory, Framework regular dialog boxes, 57 259, 262 expressions, 450 input box, 56 virtual web servers tools and software object user interface adding, 308-311 components mapping website, 450 deleting, 311 reference, 449 profile script, 188 listing, 307 NetCmdlets from Vista user account nsoftware, 450 V control, 155 PowerShell variables, 91 Analyzer, 165 constant values, 95 W documentation, 449 data types, 91-93 waiting for process download, 449 declaring, 91 ending, 271 Help, 169 example, 94 WebClient class, 300 remoting, 449 predefined, 93 websites PowerShellPlus, 19 resolution, 95 Active Directory PrimalScript, 166 VBScript command con- schema, 450 PSCX, 17, 181, 449 versions website, 451 AD Access SDK, 450 verbose parameter, Change/Break in SharePoint Provider, 449 171-172 RC2, 449 System.Management vertical line (|) for Cmdlet development documentation, 450 pipelines, 43 guidelines, 450 trial and error, 451 viewing Cmdlet help, 450 user object user commandlets list, 35 data providers, 375 mapping, 450 computer settings, ETS, 450 VBScript command 281-283 Exchange Management conversions, 451 directory content, Shell, 451 Windows PowerShell 210-212 graphical help file, 449 Index 477

WMI schema class WMI (Windows Win32_Share, 221 reference, 450 Management Win32_Startup- WPS download, 9 Instrumentation), 135 Command, 263 www.IT-Vision.de WPS classes, 135 Win32_Trustee, 226 extensions, 183 available, listing, 148 WPS support, 136 well-known security collections, date format principals, 414-416 accessing, 146 conversions, 145 WhatIf parameter, 171 IIsApplicationPool, groups, managing, where-object commandlet, 305 314-315 70, 442 IIsComputer, 305 objects wildcards, 29 IIsWebServer, 305 accessing, 137-138 Win32_Computersystem IIsWebService, 305 adapter, 139 class, 281 IIsWebVirtualDir, 305 analysis, 140 Win32_Desktop class, 315 instances, creating, 149 schema class reference Win32_LogicalDisk class object access, 137-138 website, 450 drive free space, object adapter, 139 users, managing, 314-315 viewing, 209-210 object analysis, 140 WMI Query Language drives, viewing, 207 object filtering/ (WQL), 147 Win32_NetworkAdapter- selecting, 146-147 WorkingDirectory parame- Configuration properties/methods, ter (start-process class, 296 142-144 commandlet), 270 Win32_NTLogEvent queries, 147 WPS (Windows PowerShell). class, 291 static class See also scripts Win32_Operating System members, 144 definition, 3 class, 281 System.Management benefits, 5 Win32_PerfRawData object model, 135 console, 151 class, 292 type indicators, 139 command history, Win32_Product class, 259 Win32_Computer- 186-187 Win32_Service class, 277 system, 281 command mode, 154 Win32_Share class, 221 Win32_Desktop, 315 functions, 152 Win32_StartupCommand Win32_LogicalDisk, interpreter mode, 154 class, 263 207-210 PowerTab, 156 Win32_Trustee class, 226 Win32_NetworkAdapter snap-ins, loading, windows Configuration, 296 175-176 console, 11 Win32_NTLogEvent, tab completion, 153 input, 196, 198 291 Vista user account Win32_Operating- control, 155 PropertyGrid System, 281 downloading, 8 control, 198 Win32_PerfRawData, graphical help file Windows PowerShell. 292 website, 449 See WPS Win32_Product, 259 history, 4-5 Win32_Service, 277 installing, 8-10 478 Index

interactive mode, 11-14 write-zip commandlet, console window, 11 220, 443 event logs, filtering, 14 WriteAttributes right, 405 installed services, WriteData right, 406 viewing, 13 WriteExtendedAttributes pipeline features, 13 right, 406 running processes, writing viewing, 11 binary files, 238 tab completion, 13 directory entry script mode, 14-15 attributes, 329 software inventory text files, 236-237 solution, 8 WSH software inventory uninstalling, 10 solution, 5, 7 WMI support, 136 www.IT-Visions.de WQL (WMI Query extensions, 183 Language), 147 Active Directory, Write right, 405 362-364 write-bzip2 commandlet, database access, 396-399 442 write-clipboard X–Z commandlet, XML files, 241 200, 442 checking, 242-243 write-debug commandlet, converting to XHTML 442 files, 249 write-error commandlet, customizing, 246 53, 442 DataSet exports/ write-gzip commandlet, imports, 395 442 formatting, 244 write-host commandlet, object pipeline, 248 53, 442 reading, 241 write-output commandlet, searching with XPath, 443 244 write-progress XMLDocument class, commandlet, 443 229, 244 write-tar commandlet, 443 XPath, 244 write-verbose commandlet, 443 write-warn commandlet, 53 write-warning commandlet, 443