SlideShare a Scribd company logo
PowerShell in Depth An administrator s guide Don
Jones download
https://ebookgate.com/product/powershell-in-depth-an-
administrator-s-guide-don-jones/
Get Instant Ebook Downloads – Browse at https://ebookgate.com
Get Your Digital Files Instantly: PDF, ePub, MOBI and More
Quick Digital Downloads: PDF, ePub, MOBI and Other Formats
Learn Windows PowerShell 3 in a Month of Lunches Second
Edition Don Jones
https://ebookgate.com/product/learn-windows-powershell-3-in-a-
month-of-lunches-second-edition-don-jones/
Windows PowerShell 2 0 Administrators Pocket Consultant
Administrator s Pocket Consultant 1st Edition William
R. Stanek
https://ebookgate.com/product/windows-
powershell-2-0-administrators-pocket-consultant-administrator-s-
pocket-consultant-1st-edition-william-r-stanek/
Wordpress and Ajax An In Depth Guide on Using Ajax With
WordPress 2nd Edition Edition Ronald Huereca
https://ebookgate.com/product/wordpress-and-ajax-an-in-depth-
guide-on-using-ajax-with-wordpress-2nd-edition-edition-ronald-
huereca/
Linux Mint System Administrator s Beginner s Guide 1st
Edition Arturo Fernandez Montoro
https://ebookgate.com/product/linux-mint-system-administrator-s-
beginner-s-guide-1st-edition-arturo-fernandez-montoro-2/
Linux Mint System Administrator s Beginner s Guide 1st
Edition Arturo Fernandez Montoro
https://ebookgate.com/product/linux-mint-system-administrator-s-
beginner-s-guide-1st-edition-arturo-fernandez-montoro/
Dx Rx Gynecologic Cancer Jones and Bartlett Publishers
Dx Rx Oncology Series 1st Edition Don S. Dizon
https://ebookgate.com/product/dx-rx-gynecologic-cancer-jones-and-
bartlett-publishers-dx-rx-oncology-series-1st-edition-don-s-
dizon/
Maximum PC 2005 Buyer s Guide 1st Edition George Jones
https://ebookgate.com/product/maximum-pc-2005-buyer-s-guide-1st-
edition-george-jones/
Windows PowerShell Cookbook The Complete Guide to
Scripting Microsoft s Command Shell Third Edition Lee
Holmes
https://ebookgate.com/product/windows-powershell-cookbook-the-
complete-guide-to-scripting-microsoft-s-command-shell-third-
edition-lee-holmes/
C In Depth 2nd Edition S.K. Srivastava
https://ebookgate.com/product/c-in-depth-2nd-edition-s-k-
srivastava/
M A N N I N G
Don Jones
Richard Siddaway
Jeffery Hicks
An administrator’s guide
Covers PowerShell 3.0
PowerShell in Depth
PowerShell in Depth An administrator s guide Don Jones
PowerShell in Depth
AN ADMINISTRATOR’S GUIDE
DON JONES
RICHARD SIDDAWAY
JEFFERY HICKS
M A N N I N G
SHELTER ISLAND
For online information and ordering of this and other Manning books, please visit
www.manning.com. The publisher offers discounts on this book when ordered in quantity.
For more information, please contact
Special Sales Department
Manning Publications Co.
20 Baldwin Road
PO Box 261
Shelter Island, NY 11964
Email: orders@manning.com
©2013 by Manning Publications Co. All rights reserved.
No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in
any form or by means electronic, mechanical, photocopying, or otherwise, without prior written
permission of the publisher.
Many of the designations used by manufacturers and sellers to distinguish their products are
claimed as trademarks. Where those designations appear in the book, and Manning
Publications was aware of a trademark claim, the designations have been printed in initial caps
or all caps.
Recognizing the importance of preserving what has been written, it is Manning’s policy to have
the books we publish printed on acid-free paper, and we exert our best efforts to that end.
Recognizing also our responsibility to conserve the resources of our planet, Manning books
are printed on paper that is at least 15 percent recycled and processed without the use of
elemental chlorine.
Manning Publications Co. Development editor: Cynthia Kane
20 Baldwin Road Copyeditor: Liz Welch
PO Box 261 Technical proofreader: Aleksandar Nikolic
Shelter Island, NY 11964 Proofreader: Linda Recktenwald
Typesetter: Dennis Dalinnik
Cover designer: Marija Tudor
ISBN: 9781617290558
Printed in the United States of America
1 2 3 4 5 6 7 8 9 10 – MAL – 19 18 17 16 15 14 13
v
brief contents
PART 1 POWERSHELL FUNDAMENTALS . .....................................1
1 ■ Introduction 3
2 ■ PowerShell hosts 7
3 ■ Using the PowerShell help system 17
4 ■ The basics of PowerShell syntax 29
5 ■ Working with PSSnapins and modules 39
6 ■ Operators 46
7 ■ Working with objects 60
8 ■ The PowerShell pipeline 93
9 ■ Formatting 111
PART 2 POWERSHELL MANAGEMENT ......................................127
10 ■ PowerShell Remoting 129
11 ■ Background jobs and scheduling 160
12 ■ Working with credentials 174
13 ■ Regular expressions 184
14 ■ Working with HTML and XML data 196
BRIEF CONTENTS
vi
15 ■ PSDrives and PSProviders 210
16 ■ Variables, arrays, hash tables, and scriptblocks 224
17 ■ PowerShell security 244
18 ■ Advanced PowerShell syntax 257
PART 3 POWERSHELL SCRIPTING AND AUTOMATION...............275
19 ■ PowerShell’s scripting language 277
20 ■ Basic scripts and functions 291
21 ■ Creating objects for output 301
22 ■ Scope 317
23 ■ PowerShell workflows 332
24 ■ Advanced syntax for scripts and functions 359
25 ■ Script modules and manifest modules 379
26 ■ Custom formatting views 391
27 ■ Custom type extensions 403
28 ■ Data language and internationalization 417
29 ■ Writing help 429
30 ■ Error handling techniques 435
31 ■ Debugging tools and techniques 447
32 ■ Functions that work like cmdlets 466
33 ■ Tips and tricks for creating reports 485
PART 4 ADVANCED POWERSHELL ...........................................495
34 ■ Working with the Component
Object Model (COM) 497
35 ■ Working with .NET Framework objects 505
36 ■ Accessing databases 517
37 ■ Proxy functions 525
38 ■ Building a GUI 538
39 ■ WMI and CIM 557
40 ■ Best practices 584
vii
contents
preface xxi
acknowledgments xxiii
about this book xxv
about the authors xxvii
about the cover illustration xxix
PART 1 POWERSHELL FUNDAMENTALS. ..........................1
1 Introduction 3
1.1 Who this book is for 3
1.2 What this book will teach you 4
1.3 What this book won’t teach you 4
1.4 Where we drew the line 5
1.5 Beyond PowerShell 5
1.6 Ready? 6
2 PowerShell hosts 7
2.1 32-bit vs. 64-bit, and administrator vs. not 8
2.2 The console 10
2.3 The PowerShell ISE 12
CONTENTS
viii
2.4 Command history buffer vs. PowerShell’s history 15
2.5 Transcripts 16
2.6 Summary 16
3 Using the PowerShell help system 17
3.1 The help commands 17
3.2 Where’s the help? 18
3.3 Using the help 20
3.4 “About” help files 23
3.5 Provider help 24
3.6 Interpreting command help 25
3.7 Common parameters 27
3.8 Summary 28
4 The basics of PowerShell syntax 29
4.1 Commands 30
Aliases: nicknames for commands 31 ■ Command name
tab completion 32
4.2 Parameters 32
Truncating parameter names 34 ■ Parameter name
tab completion 35
4.3 Typing trick: line continuation 35
4.4 Parenthetical commands and expressions 36
4.5 Script blocks 37
4.6 Summary 38
5 Working with PSSnapins and modules 39
5.1 There’s only one shell 39
5.2 PSSnapins vs. modules 40
5.3 Loading, autoloading, and profiles 41
5.4 Using extensions 41
Discovering extensions 41 ■
Loading extensions 43
Discovering extensions’ additions 43 ■
Managing extensions 44
5.5 Command name conflicts 44
5.6 Managing module autoloading 45
5.7 Summary 45
CONTENTS ix
6 Operators 46
6.1 Logical and comparison operators 47
The –contains operator 48 ■
The -in and -notin operators 49
Boolean, or logical, operators 50 ■
Bitwise operators 51
6.2 Arithmetic operators 53
6.3 Other operators 55
String and array manipulation operators 55
Object type operators 56 ■
Format operator 57
Miscellaneous operators 58
6.4 Summary 59
7 Working with objects 60
7.1 Introduction to objects 61
7.2 Members: properties, methods, and events 63
7.3 Sorting objects 68
7.4 Selecting objects 69
Use 1: choosing properties 70 ■
Use 2: choosing a subset
of objects 71 ■
Use 3: making custom properties 73
Use 4: extracting and expanding properties 75
Use 5: choosing properties and a subset of objects 79
7.5 Filtering objects 79
Simplified syntax 79 ■
Full syntax 81
7.6 Grouping objects 81
7.7 Measuring objects 83
7.8 Enumerating objects 84
Full syntax 85 ■
Simplified syntax 85
7.9 Importing, exporting, and converting objects 86
7.10 Comparing objects 90
7.11 Summary 92
8 The PowerShell pipeline 93
8.1 How the pipeline works 93
The old way of piping 94 ■
The PowerShell way of piping 95
8.2 Parameter binding ByValue 96
8.3 Pipeline binding ByPropertyName 98
8.4 Troubleshooting parameter binding 104
CONTENTS
x
8.5 When parameter binding lets you down 109
8.6 The pipeline with external commands 110
8.7 Summary 110
9 Formatting 111
9.1 The time to format 111
9.2 The formatting system 113
Is there a predefined view? 113 ■
What properties should
be displayed? 113 ■
List or table? 114
9.3 The Format cmdlets 114
Formatting wide lists 114 ■
Formatting tables 115
Formatting lists 120 ■
Same objects, different formats 122
9.4 Eliminating confusion and “gotchas” 122
Formatting is the end of the line 122 ■
Select or format? 123
Format, out, export—which? 124
9.5 Summary 125
PART 2 POWERSHELL MANAGEMENT ..........................127
10 PowerShell Remoting 129
10.1 The many forms of remote control 130
10.2 Remoting overview 130
Authentication 131 ■
Firewalls and security 132
10.3 Using Remoting 132
Enabling Remoting 132 ■
1-to-1 Remoting 133
1-to-many Remoting 134 ■
Remoting caveats 136
Remoting options 138
10.4 PSSessions 140
Creating a persistent session 140 ■
Using a session 140
Managing sessions 141 ■
Disconnecting and
reconnecting sessions 141
10.5 Advanced session techniques 144
Session parameters 144 ■
Session options 145
10.6 Creating a custom endpoint 145
Custom endpoints for delegated administration 147
CONTENTS xi
10.7 Connecting to nondefault endpoints 148
10.8 Enabling the “second hop” 149
10.9 Setting up WinRM listeners 150
10.10 Other configuration scenarios 152
Cross-domain Remoting 152 ■ Quotas 153 ■ Configuring on
a remote machine 154 ■ Key WinRM configuration settings 154
Adding a machine to your Trusted Hosts list 155 ■ Using Group
Policy to configure Remoting 156
10.11 Implicit Remoting 157
10.12 Summary 159
11 Background jobs and scheduling 160
11.1 Remoting-based jobs 160
Starting jobs 161 ■
Checking job status 162 ■
Working with
child jobs 162 ■
Waiting for a job 164 ■
Stopping jobs 164
Getting job results 164 ■
Removing jobs 165
Investigating failed jobs 166
11.2 WMI jobs 166
11.3 Scheduled jobs 167
Scheduled jobs overview 168 ■
Creating a scheduled job 168
Managing scheduled jobs 169 ■
Working with scheduled
job results 170
11.4 Job processes 170
Jobs created with Start-Job 171 ■
Jobs created with
Invoke-Command 172 ■
Jobs created through the WMI
cmdlets 173 ■
Jobs created through the scheduler 173
11.5 Summary 173
12 Working with credentials 174
12.1 About credentials 175
12.2 Using credentials 178
12.3 Crazy credentials ideas 179
Packaging your script 179 ■
Saving a credential object 179
Creating a credential without the GUI 181
Supporting credentials in your script 181
12.4 Summary 183
CONTENTS
xii
13 Regular expressions 184
13.1 Basic regular expression syntax 185
13.2 The –match operator 188
13.3 The select-string cmdlet 190
13.4 Switch statement 190
13.5 The REGEX object 192
13.6 Summary 195
14 Working with HTML and XML data 196
14.1 Working with HTML 196
Retrieving an HTML page 197 ■
Working with the
HTML results 198 ■
Practical example 201
Creating HTML output 202
14.2 Working with XML 206
Using XML to persist data 206 ■
Reading arbitrary
XML data 207 ■
Creating XML data and files 208
Using XML XPath queries 209
14.3 Summary 209
15 PSDrives and PSProviders 210
15.1 Why use PSProviders? 210
15.2 What are PSProviders? 211
15.3 What are PSDrives? 212
15.4 Working with PSDrives 213
Working with PSDrive items 214 ■ Working with
item properties 216
15.5 Transactional operations 219
15.6 Every drive is different 221
15.7 Summary 223
16 Variables, arrays, hash tables, and scriptblocks 224
16.1 Variables 224
Variable names 225 ■ Variable types 226 ■ Being strict
with variables 228
16.2 Built-in variables and the Variable: drive 230
16.3 Variable commands 231
CONTENTS xiii
16.4 Arrays 232
16.5 Hash tables and ordered hash tables 235
Ordered hash tables 239 ■
Common uses for hash tables 241
Defining default parameter values 241
16.6 Scriptblocks 241
16.7 Summary 243
17 PowerShell security 244
17.1 PowerShell security goals 244
17.2 PowerShell security mechanisms 245
Script execution requires a path 245
Filename extension associations 246
17.3 Execution policy 247
A digital signature crash course 247 ■
Understanding script
signing 249 ■
The execution policy in depth 251
17.4 The PowerShell security debate 255
17.5 Summary 256
18 Advanced PowerShell syntax 257
18.1 Splatting 257
18.2 Defining default parameter values 259
18.3 Running external utilities 263
18.4 Expressions in quotes: $($cool) 269
18.5 Parentheticals as objects 270
18.6 Increase the format enumeration limit 271
18.7 Hash tables as objects 272
18.8 Summary 274
PART 3 POWERSHELL SCRIPTING AND AUTOMATION ...275
19 PowerShell’s scripting language 277
19.1 Defining conditions 277
19.2 Loops: For, Do, While, Until 278
The For loop 278 ■
The other loops 280
19.3 ForEach 281
19.4 Break and Continue 283
CONTENTS
xiv
19.5 If . . . ElseIf . . . Else 284
19.6 Switch 286
19.7 Mastering the punctuation 289
19.8 Summary 290
20 Basic scripts and functions 291
20.1 Script or function? 291
20.2 Execution lifecycle and scope 292
20.3 Starting point: a command 293
20.4 Accepting input 293
20.5 Creating output 295
20.6 “Filtering” scripts 297
20.7 Moving to a function 299
20.8 Summary 300
21 Creating objects for output 301
21.1 Why output objects? 302
21.2 Syntax for creating custom objects 303
Technique 1: using a hash table 303 ■
Technique 2: using
Select-Object 305 ■
Technique 3: using Add-Member 306
Technique 4: using a Type declaration 307
Technique 5: creating a new class 307
What’s the difference? 309
21.3 Complex objects: collections as properties 309
21.4 Applying a type name to custom objects 312
21.5 So, why bother? 313
21.6 Summary 316
22 Scope 317
22.1 Understanding scope 317
22.2 Observing scope in action 321
22.3 Dot sourcing 323
22.4 Manipulating cross-scope elements 324
22.5 Being private 328
22.6 Being strict 328
22.7 Summary 331
CONTENTS xv
23 PowerShell workflows 332
23.1 Workflow overview 333
23.2 Workflow basics 334
Common parameters for workflows 335 ■
Activities and
stateless execution 335 ■
Persisting state 337
Suspending and resuming workflows 337
Workflow limitations 337 ■
Parallelism 340
23.3 General workflow design strategy 341
23.4 Example workflow scenario 342
23.5 Writing the workflow 342
23.6 Workflows vs. functions 343
23.7 Specific workflow techniques 345
Sequences 345 ■
InlineScript 346
23.8 Running a workflow 349
Workflow jobs 349 ■
Suspending and restarting
a workflow 350 ■
Workflow credentials 351
23.9 A practical example 351
23.10 Invoke-AsWorkflow 353
23.11 PSWorkflowSession 355
23.12 Troubleshooting a workflow 357
23.13 Summary 358
24 Advanced syntax for scripts and functions 359
24.1 Starting point 360
24.2 Advanced parameters 360
24.3 Variations on parameter inputs 365
24.4 Parameter aliases 366
24.5 Parameter validation 367
24.6 Parameter sets 372
24.7 WhatIf and Confirm parameters 373
24.8 Verbose output 375
24.9 Summary 378
25 Script modules and manifest modules 379
25.1 Making a script module 380
25.2 Exporting module members 382
CONTENTS
xvi
25.3 Making a module manifest 386
25.4 Creating dynamic modules 387
25.5 Summary 390
26 Custom formatting views 391
26.1 Object type names 392
26.2 Getting view templates 393
26.3 Starting a view file 393
26.4 Adding view types 394
26.5 Importing view data 397
26.6 Using named views 399
26.7 Going further 401
26.8 Summary 402
27 Custom type extensions 403
27.1 What are type extensions? 404
27.2 Creating and loading a type extension file 405
27.3 Making type extensions 407
AliasProperty 407 ■
ScriptProperty 407 ■
ScriptMethod 408
DefaultDisplayPropertySet 409
27.4 A complete example 409
27.5 Updating type data dynamically 411
27.6 Get-TypeData 414
27.7 Remove-TypeData 415
27.8 Summary 416
28 Data language and internationalization 417
28.1 Internationalization basics 418
28.2 Adding a data section 420
28.3 Storing translated strings 422
28.4 Testing localization 425
28.5 Summary 428
29 Writing help 429
29.1 Comment-based help 430
29.2 Writing About topics 432
CONTENTS xvii
29.3 XML-based help 432
29.4 Summary 434
30 Error handling techniques 435
30.1 About errors and exceptions 436
30.2 Using $ErrorActionPreference and –ErrorAction 436
30.3 Using –ErrorVariable 438
30.4 Using $Error 439
30.5 Trap constructs 440
30.6 Try...Catch...Finally constructs 443
30.7 Summary 446
31 Debugging tools and techniques 447
31.1 Debugging: all about expectations 448
31.2 Write-Debug 456
31.3 Breakpoints 460
31.4 Using Set-PSDebug 463
31.5 Debugging in third-party editors 465
31.6 Summary 465
32 Functions that work like cmdlets 466
32.1 Defining the task 467
32.2 Building the command 468
32.3 Parameterizing the pipeline 469
32.4 Adding professional features 472
32.5 Error handling 472
Adding verbose and debug output 474 ■
Defining a custom
object name 477
32.6 Making it a function and adding help 477
32.7 Creating a custom view 479
32.8 Creating a type extension 480
32.9 Making a module manifest 481
32.10 Summary 484
CONTENTS
xviii
33 Tips and tricks for creating reports 485
33.1 What not to do 485
33.2 Working with HTML fragments and files 487
Getting the information 488 ■
Producing an
HTML fragment 488 ■
Assembling the final HTML page 489
33.3 Sending email 492
33.4 Summary 493
PART 4 ADVANCED POWERSHELL ...............................495
34 Working with the Component Object Model (COM) 497
34.1 Introduction to COM objects 498
34.2 Instantiating COM objects in PowerShell 500
34.3 Accessing and using COM objects’ members 500
34.4 PowerShell and COM examples 503
34.5 Summary 504
35 Working with .NET Framework objects 505
35.1 Classes, instances, and members 506
35.2 .NET Framework syntax in PowerShell 507
35.3 .NET support in PowerShell 508
35.4 Accessing static members 509
35.5 Finding the right framework bits 509
35.6 Creating and working with instances 514
35.7 Summary 516
36 Accessing databases 517
36.1 Native SQL vs. OLEDB 518
36.2 Connecting to data sources 518
36.3 Querying data 519
Databases with DataAdapters 520 ■
Databases with
DataReaders 520
36.4 Adding, changing, and deleting data 521
36.5 Calling stored procedures 521
36.6 A module to make it easier 522
36.7 Summary 524
CONTENTS xix
37 Proxy functions 525
37.1 The purpose of proxy functions 525
37.2 How proxy functions work 526
37.3 Creating a basic proxy function 526
37.4 Adding a parameter 528
37.5 Removing a parameter 532
37.6 Turning it into a function 534
37.7 Summary 536
38 Building a GUI 538
38.1 WinForms via PowerShell Studio 539
Creating the GUI 540 ■
Adding the code 543
Using the script 548
38.2 Windows Presentation Foundation (WPF) and ShowUI 552
38.3 WinForms vs. WPF 554
38.4 Ideas for leveraging a GUI tool 555
38.5 Summary 556
39 WMI and CIM 557
39.1 What is WMI? 558
39.2 WMI cmdlets 559
Get-WmiObject 559 ■
Remove-WmiObject 561
Set-WmiInstance 562 ■
Invoke-WmiMethod 563
Register-WmiEvent 566
39.3 CIM cmdlets 567
Get-CIMClass 570 ■
Get-CimInstance 571
Remove-CimInstance 573 ■
Set-CimInstance 574
Invoke-CimMethod 574 ■
Register-CimIndicationEvent 575
39.4 CIM sessions 576
39.5 “Cmdlets over objects” 578
39.6 Summary 583
40 Best practices 584
40.1 PowerShell general best practices 584
40.2 PowerShell scripting best practices 585
40.3 PowerShell in the enterprise best practices 587
index 589
PowerShell in Depth An administrator s guide Don Jones
xxi
preface
Windows PowerShell is viewed by many IT professionals as a necessary evil; we see it as
a management marvel. The challenge from the beginning has been to wrap one’s
head around the PowerShell paradigm of an object-based shell. Some people view
PowerShell as just another scripting language like VBScript. The truth is that Power-
Shell is an automation and management engine. You can run this engine in a tradi-
tional console application, which is how most IT pros are first exposed to it. You can
run it in a graphical environment like the PowerShell Integrated Scripting Environ-
ment (ISE), or through a third-party tool like PowerGUI or PowerShell Plus.
As you might imagine, the third version of a product offers substantially more fea-
tures and benefits than the first, and PowerShell 3.0 fits this model. This version of
PowerShell naturally builds on what came before, but it takes off from there. If you
think of Windows 8 and Windows Server 2012 as operating systems for the cloud,
then PowerShell 3.0 is the automation and management engine for the cloud, although
PowerShell “scales down” to help you better manage any size environment.
Collectively, we have close to 70 years of IT experience. We have worked with
PowerShell from its days as a beta product and have written on the topic for nearly as
long. Our goal is to bring this knowledge and experience into a single reference book.
Notice the key word, “reference.” This is not a how-to or teach yourself PowerShell
book, although you can learn much from reading it cover to cover. Rather, this book is
intended as the reference guide you keep at your desk or on your mobile device so
that when you need to better understand a topic, like PowerShell remoting, you have
a place to which you can turn.
PREFACE
xxii
We have tried to keep our examples practical and targeted towards IT professionals
responsible for Windows system administration. It is our hope that this will be the
book you go to for answers.
xxiii
acknowledgments
As you can imagine, a book of this scope and magnitude is not an easy undertaking,
even with three coauthors. There are many, many people who had a hand in mak-
ing this possible. First, we’d like to thank the entire PowerShell product team at
Microsoft. Many of them took time from their busy schedules to answer our ques-
tions and offer guidance on a number of new features, even while they were still
being developed!
The authors would also like to thank the fine folks at Manning Publications:
Cynthia Kane, Karen Miller, Maureen Spencer, Liz Welch, Linda Recktenwald, Janet
Vail, and Mary Piergies. They have taken what can be a grueling process and turned it
into something pleasant yet productive in helping us bring this book to publication.
That is not easy.
We also thank the cadre of what we think of as “real-world” reviewers who offered
their opinions on how we could make this a book that they, and you, would want on
your bookshelf. They include Adam Bell, Andre Sune, Bart Vermeulen, Bruno
Gomes, Eric Flamm, Eric Stoker, Gary Walker, Greg Heywood, Innes Fisher, James
Berkenbile, Jelmer Siljee, Jonathan Medd, Kais Ayari, Klaus Schulte, Mike Shepard,
Peter Monadjemi, Richard Beckett, Rolf Åberg, Santiago I. Cánepa, Thomas Lee,
and Trent Whiteley.
We would especially like to thank Aleksandar Nikolic for his time and dedication
in reviewing the technical content of our book. Aleksandar shares our desire to pro-
duce the best possible PowerShell reference and we truly appreciate his efforts.
ACKNOWLEDGMENTS
xxiv
DON would like to thank everyone at Manning for their support of, and commitment
to, this project. He’d also like to thank his coauthors for their hard work, and his fam-
ily for being so giving of their time.
RICHARD would like to thank everyone who has taken the time to comment on the
book and the PowerShell community for their willingness to share. He would like to
thank Don and Jeff for making this a very enjoyable experience—working across eight
timezones makes for some interesting conversations.
JEFF would like to extend a special thanks to Steve Murawski and Travis Jones for their
PowerShell 3.0 insights. He would also like to thank his coauthors for making this one
of the best authoring experiences possible.
xxv
about this book
This book was written as a reference for system administrators. You can read the book
cover to cover, and we’ve tried to arrange the chapters in a logical progression, but, in
the end, it works best as a reference, where you can explore a topic more deeply in the
chapter that is devoted to a particular subject. Chapter 1 will tell you more about what
you will learn in the book, and what you need to know before you start.
The 40 chapters in the book are arranged into four parts, as follows:
■ Part 1 “Fundamentals” includes chapters 1 through 9 which cover the basics
associated with using PowerShell. Although we didn’t write this book as a tuto-
rial, there are a few basics you’ll need to explore before you can use PowerShell
effectively: the pipeline, the concept of PowerShell hosts, the shell’s help sys-
tem, and so forth. We’ll dive deeper into some of these topics than a tutorial
normally would, so even if you’re already familiar with these foundational con-
cepts, it’s worth a quick read-through of these chapters.
■ Part 2 “PowerShell management” covers topics such as remote control, back-
ground jobs, regular expressions, and HTML and XML. These are just a few of
the core technologies accessible within PowerShell that make server and client
management easier, more scalable, and more effective. Chapters 10 through 18
tackle these technologies individually, and we dive as deeply as we can into
them, so that you can master their intricacies and subtleties.
■ Part 3 “PowerShell Scripting and Automation” includes chapters 19 through 33
which have a single goal: repeatability. Using PowerShell’s scripting language,
ABOUT THIS BOOK
xxvi
along with associated technologies like workflow, you can begin to create reus-
able tools that automate key tasks and processes in your environment.
■ Part 4 “Advanced PowerShell” consists of chapters 34 through 40. One of Power-
Shell’s greatest strengths is its ability to connect to other technologies, such as
WMI, CIM, COM, .NET, and a host of other acronyms. The chapters in part 4
look at each of these and demonstrate how PowerShell can utilize them. We
give you a starting place for doing this, and then we provide you with some
direction for further independent exploration.
Code conventions and downloads
All source code in listings or in text is in a fixed-width font like this to separate it
from ordinary text. Code annotations accompany many of the listings, highlighting
important concepts. In some cases, numbered bullets link to explanations that follow
the listing.
The code samples are based on PowerShell 3.0. We intended the samples to be
instructive, but we did not design them for production use. They may not always
be the “best” PowerShell—our code examples were designed to reinforce concepts
and make points.
We have tried to fit code samples into the confines of a printed page, which means
that sometimes we have had to bend some rules. You are welcome to try the code snip-
pets on your computer, but remember that the book is not intended as a tutorial. Lon-
ger code samples are displayed as code listings; we don’t expect you to type these. If
you want to try them, the files can be downloaded from the book’s page on the pub-
lisher’s website at www.manning.com/PowerShellinDepth.
We, along with our technical reviewer, have strived to test and retest everything.
But sometimes errors will still sneak through. We encourage you to use the Author
Online forum for this book at www.manning.com/PowerShellinDepth to post any cor-
rections, as well as your comments or questions on the book’s content.
Author Online
Purchase of PowerShell in Depth includes free access to a private web forum run by
Manning Publications, where you can make comments about the book, ask technical
questions, and receive help from the authors and from other users. To access the forum
and subscribe to it, point your web browser to www.manning.com/PowerShellinDepth.
This page provides information on how to get on the forum once you are registered,
what kind of help is available, and the rules of conduct on the forum.
Manning’s commitment to our readers is to provide a venue where a meaningful dia-
logue between individual readers and between readers and the authors can take place.
It is not a commitment to any specific amount of participation on the part of the
authors, whose contribution to the book’s forum remains voluntary (and unpaid). We
suggest you try asking the authors some challenging questions, lest their interest stray!
The Author Online forum and the archives of previous discussions will be accessi-
ble from the publisher’s website as long as the book is in print.
xxvii
about the authors
DON JONES has more than 20 years of experience in the IT industry, and is a recog-
nized expert in Microsoft’s server platform. He’s a multiple-year recipient of Micro-
soft’s prestigious Most Valuable Professional (MVP) award, and writes the “Windows
PowerShell” column for Microsoft TechNet Magazine. Don has authored more than
50 books on information technology topics, including three books in the popular
Learn PowerShell in a Month of Lunches series from Manning. He is a regular and top-
rated speaker at numerous technology conferences and symposia worldwide, and a
founding director of PowerShell.org, a community-owned and community-operated
resource for PowerShell users.
RICHARD SIDDAWAY has been working with Microsoft technologies for over 20 years
having spent time in most IT roles. He has always been interested in automation tech-
niques (including automating job creation and submission on mainframes many years
ago). PowerShell caught his interest and Richard has been using it since the early
beta versions. He regularly blogs about PowerShell, and using PowerShell, at http:/
/
msmvps.com/blogs/richardsiddaway/default.aspx. Richard founded and still runs the
UK PowerShell User Group and has been a PowerShell MVP for the last five years. A
regular speaker and writer on PowerShell topics, his previous Manning books include
PowerShell in Practice and PowerShell and WMI.
JEFFERY HICKS is a Microsoft MVP in Windows PowerShell, Microsoft Certified Trainer
and an IT veteran with 20 years of experience, much of it spent as an IT consultant
ABOUT THE AUTHORS
xxviii
specializing in Microsoft server technologies. He works today as an independent
author, trainer, and consultant, and he has coauthored two earlier books for Manning.
Jeff writes the popular Prof. PowerShell column for MPCMag.com and is a regular
contributor to the Petri IT Knowledgebase. You can keep up with Jeff at his blog
http:/
/jdhitsolutions.com/blog or on Twitter @jeffhicks
The authors would love to hear from you and are eager to help spread the good news
about PowerShell. We hope you’ll come up to us at conferences like TechEd and let us
know how much (hopefully) you enjoyed the book. If you have any other PowerShell
questions, we encourage you to use the forums at PowerShell.org, where we all are
active participants.
xxix
about the cover illustration
The figure on the cover of PowerShell in Depth is captioned a “Man from Split, Dalmatia.”
The illustration is taken from the reproduction published in 2006 of a 19th-century
collection of costumes and ethnographic descriptions entitled Dalmatia by Professor
Frane Carrara (1812–1854), an archaelogist and historian and the first director of the
Musuem of Antiquity in Split, Croatia. The illustrations were obtained from a helpful
librarian at the Ethnographic Museum (formerly the Museum of Antiquity), itself situ-
ated in the Roman core of the medieval center of Split: the ruins of Emperor Diocle-
tian’s retirement palace from around AD 304. The book includes finely colored
illustrations of figures from different regions of Croatia, accompanied by descriptions
of the costumes and of everyday life.
The man on the cover is wearing dark blue woolen trousers and a black vest over a
white linen shirt. Over his shoulder is a brown jacket, and a red belt and a red cap
complete the outfit; in his hand he holds a long pipe. The elaborate and colorful
embroidery on his costume is typical for this region of Croatia.
Dress codes have changed since the 19th century and the diversity by region, so
rich at the time, has faded away. It is now hard to tell apart the inhabitants of different
continents, let alone different towns or regions. Perhaps we have traded cultural diver-
sity for a more varied personal life—certainly for a more varied and fast-paced techno-
logical life.
We at Manning celebrate the inventiveness, the initiative, and, yes, the fun of the
computer business with book covers based on the rich diversity of regional life of two
centuries ago‚ brought back to life by the pictures from this collection.
PowerShell in Depth An administrator s guide Don Jones
Part 1
PowerShell fundamentals
In part 1, we’ll cover some of the basics associated with using PowerShell.
Although we didn’t write this book as a tutorial, there are nonetheless a few
basics you’ll need to explore before you can use PowerShell effectively: the pipe-
line, the concept of PowerShell hosts, the shell’s help system, and so forth. We’ll
dive a bit deeper into some of these topics than a tutorial normally might do, so
even if you’re already familiar with these foundational concepts, it’s worth a quick
read-through of these chapters.
PowerShell in Depth An administrator s guide Don Jones
3
Introduction
As of this writing, Windows PowerShell is approaching its sixth year of existence
and in its third major release. In that time, it’s changed the way people look at
administering many Microsoft, and even some non-Microsoft, products. Although
the graphical user interface (GUI) will always be an important part of administra-
tion in many ways, PowerShell has given administrators options: Use an easy, intui-
tive GUI; manage from a rich, interactive command-line console; or fully automate
a simple scripting language. We’re delighted that so many administrators have
started using PowerShell, and we’re honored that you’ve chosen this book to fur-
ther your own PowerShell education.
1.1 Who this book is for
We wrote this book for system administrators, not developers. In the Microsoft
world, administrators go by the catchall title “IT professional” or “IT pro” and that’s
who we had in mind. As such, we assume you’re not a full-time programmer,
This chapter covers
■ What the book will and won’t teach
■ The boundaries of this book
■ Going beyond PowerShell
4 CHAPTER 1 Introduction
although if you have some programming or scripting experience it’ll make certain
parts of PowerShell easier to learn.
We assume you’re primarily interested in automating various administrative tasks
and processes, or at least being more efficient, but we don’t make any assumptions
about the products with which you work. You may be an Exchange Server administra-
tor, or maybe SharePoint or SQL Server is your thing. Perhaps you manage Active
Directory, or you’re in charge of file servers. You may even manage a Citrix or
VMware environment (yes, they can be managed by PowerShell). It doesn’t matter,
because what we’ll focus on in this book is the core technologies of PowerShell itself:
the techniques and features you’ll need to use no matter what products you’re
administering. We do use Active Directory in a few examples, but every technique,
pattern, practice, and trick we show you will apply equally well, no matter where
you’ve chosen to use PowerShell.
1.2 What this book will teach you
You can certainly read this book cover to cover, and we’ve tried to arrange the chap-
ters in a logical progression. But in the end, we intend for this book to be a reference.
Need to figure out PowerShell Remoting? Skip to that chapter. Confused about how
commands pipe data from one to another? We’ve written a chapter for that. Need to
access a database from within a PowerShell script? There’s a chapter for that.
We’ve no intention of making you a programmer—we don’t claim to be program-
mers—we all have backgrounds as IT pros. Yes, PowerShell can support some robust
scripts, but you can also accomplish a lot by running commands. If you have program-
ming experience, it’ll serve you well, and you may be tempted to approach PowerShell
more as a scripting language, which is fine. If you’ve never scripted or programmed a
single line of code, you’ll probably see PowerShell as a pure command-line interface,
where you run commands to make stuff happen, and that’s fine, too. Either way you
win because you get to automate your tedious, repetitive work.
1.3 What this book won’t teach you
We assume you’re already an experienced administrator and that you’re familiar with
the inner workings of whatever technology you manage. We aren’t going to teach you
what an Active Directory user account is, or what an Exchange mailbox does, or how
to create a SharePoint site. PowerShell is a tool that lets you accomplish administrative
tasks, but like any tool it assumes you know what you’re doing.
To use a noncomputer analogy, PowerShell is a hammer, and this book will teach
you how to swing that hammer and not smash your thumb. We won’t teach you about
building houses, though—we assume you already know how to do that, and you’re
looking for a more efficient way to do it than pounding nails with a rock.
5
Beyond PowerShell
1.4 Where we drew the line
It’s safe to say that PowerShell can’t do everything for you. You’ll find some things with
which it’s completely incapable of helping, as with any technology. But you’ll also find
tasks for which PowerShell works well. And you’ll encounter that weird middle
ground where you could do something in PowerShell, but to do it you’d have to go
beyond the strict boundaries of what PowerShell is.
For example, PowerShell doesn’t natively contain a way to map a network printer.
You could instantiate a Component Object Model (COM) object to accomplish the
task from within PowerShell, but it has nothing to do with PowerShell. Instead, it’s
the shell giving you a way to access completely external technologies. In these cases
(which are becoming increasingly rare in the latest version of Windows), we’ll only
say, “You can’t do that in PowerShell yet.” We know our statement isn’t 100 percent
true, but we want to keep this book focused on what PowerShell is and what it does
natively. If we turn this book into “everything you can do with PowerShell natively, plus
all the external stuff like .NET and COM and so on that you can get to from Power-
Shell,” it’d grow to 7,000 pages in length and we’d never finish.
That said, we’re including material in the book on using some of these external
technologies, along with some guidance on where you can find resources to educate
yourself on them more completely if you’ve a mind to do so.
1.5 Beyond PowerShell
PowerShell is a lot like the Microsoft Management Console (MMC), with which you’re
probably familiar. On its own, it’s useless. Both the MMC and PowerShell only become
useful when you add extensions, which in the MMC would be “snap-ins,” and in Power-
Shell would be either a “snap-in” or a “module.” Those extensions give you access to
Exchange, Active Directory, SharePoint, SQL Server, and so on.
Understand that the folks at Microsoft who write PowerShell don’t write the exten-
sions. They provide some tools and rules for the developers who do create extensions,
but their job is to create the core PowerShell stuff. Extensions are made by other
product teams: The Exchange team makes the Exchange PowerShell extension, the
Active Directory team makes its extension, and so on. If you’re looking at a particular
extension and don’t like what you see, blame the product team that produced it, not
PowerShell. If you’d like to administer something—maybe WINS Server, for exam-
ple—and PowerShell has no way to administer it, it’s not the PowerShell team’s fault.
Blame the owners of the technology you’re trying to work with, and encourage them
to get on board and produce a PowerShell extension for their product.
This division of labor is one reason why we’re keeping this book focused on the
core of PowerShell. That core is what you’ll use no matter what extensions you end up
deploying to achieve your administrative goals.
6 CHAPTER 1 Introduction
1.6 Ready?
Okay, that’s enough of an introduction. If you want to follow along, make sure you
have PowerShell v3 installed on a Windows 7 Desktop, or run a Windows 8 client.
Now, pick a chapter and jump in.
7
PowerShell hosts
PowerShell can be confusing to use because it behaves differently in different situ-
ations. Here’s an example from PowerShell v2: When you run the Read-Host com-
mand in the PowerShell.exe console, it behaves differently than if you run that
same command in the PowerShell Integrated Scripting Editor (ISE). The reason
you encounter these differences has to do with the fact that you don’t interact
directly with PowerShell. Instead, you give commands to the PowerShell engine by
means of a host. It’s up to the host to determine how to interact with the Power-
Shell engine.
NOTE The difference in the response of Read-Host between the console
and the ISE has been eliminated in PowerShell v3.
This chapter covers
■ The purpose of PowerShell hosts
■ The PowerShell console and ISE hosts
■ The differences between 64-bit and
32-bit hosts
■ PowerShell transcripts
8 CHAPTER 2 PowerShell hosts
The PowerShell engine is a set of .NET Framework classes stored in a DLL file. You
can’t interact with it directly. Instead, the application you interact with loads the
engine. For example, if you’ve ever used the Exchange Server 2007 (or later) graphi-
cal management console (called the Exchange Management Console, or EMC), then
you’ve used a PowerShell host. The EMC lets you interact by clicking icons, filling in
dialog boxes, and so forth, but it’s PowerShell that performs the actions it takes. You
never “see” the shell, but it’s hiding under the GUI. That’s why it can show you the
PowerShell commands for the actions it has performed. Exchange also provides a
console-based shell that exposes the underlying PowerShell engine.
When we talk about “using PowerShell,” we’re most often talking about using it
through a host that looks more like a command-line shell. Microsoft provides two dif-
ferent hosts for that purpose: the console and the ISE. Third-party vendors can also pro-
duce host applications, and many popular PowerShell editors—PrimalScript, PowerGUI,
PowerShell Plus, PowerSE, and so forth—all host the PowerShell engine. How you
interact with the shell and what your results look like will depend on the host you’re
using. Results might look and work one way in the Microsoft-supplied console, but
they might look and work differently in a third-party application—or in some cases
may not work at all. Conversely, some things that have worked in a third-party host
don’t work in the Microsoft hosts.
TIP Remember that if things work in one host but not in another, it’s mostly
likely due to the differences in the hosts rather than it being a PowerShell error.
For this book, we’ll assume you’re using one of the two Microsoft-supplied hosts,
which we’ll describe in this chapter.
2.1 32-bit vs. 64-bit, and administrator vs. not
The way you access the shortcuts for Microsoft’s PowerShell host applications depends
on the version of the operating system and the install options you’ve chosen. The first
thing you need to be aware of is that PowerShell v3 isn’t available on all versions of
Windows. It’s installed as part of the base build on
■ Windows 8 x86 and x64
■ Windows Server 2012 x64
The Windows Management Foundation (WMF) download (PowerShell v3, WinRM v3,
and the new WMI API) is available for
■ Windows 7 SP1 (or above) x86 and x64
■ Windows Server 2008 R2 SP1 (or above) x64
■ Windows Server 2008 SP2 (or above) x86 and x64
The WMF download is available from www.microsoft.com/en-us/download/details.aspx?
id=34595. Check the version you need for your system in the download instructions.
NOTE If you’re using Windows XP, Windows Vista, or any flavor of Windows
Server 2003, you can’t install PowerShell v3.
9
32-bit vs. 64-bit, and administrator vs. not
In Windows 8 and Windows Server 2012, the way you access applications has changed.
You use the Start screen instead of the Start menu. If you’re on the Windows Desktop,
press the Win button to access the Start screen. Scroll to the right to find the Power-
Shell icon. Alternatively, press Win-Q to access the application search menu.
On earlier versions of Windows you’ll find shortcuts to Microsoft’s host applica-
tions on your computer’s Start menu. If you’re on a Server Core (Windows Server
2008 R2 or later) system that doesn’t have a Start menu, run powershell to start the
console host. You’ll need to install PowerShell because it isn’t part of the default Win-
dows Server 2008 R2 server core install. The shortcuts can usually be found under
Accessories > Windows PowerShell.
NOTE PowerShell and the old command prompt use the same underlying
console technology, which means you can type PowerShell in a command
prompt or cmd in a PowerShell console and “switch” to the other shell. Typing
Exit will revert back to the starting shell.
On a 32-bit system (on any Windows version), you’ll find shortcuts for PowerShell—what
we refer to as “the console”—and for the PowerShell ISE. Obviously, these shortcuts both
point to 32-bit versions of PowerShell. But on a 64-bit system you’ll find four shortcuts:
■ Windows PowerShell—the 64-bit console
■ Windows PowerShell ISE—also 64-bit
■ Windows PowerShell (x86)—the 32-bit console
■ Windows PowerShell ISE (x86)—also 32-bit
It’s important to run the proper version, either 32-bit or 64-bit. PowerShell itself
behaves the same either way, but when you’re ready to load extensions you can only
load ones built on the same architecture. The 64-bit shell can only load 64-bit exten-
sions. If you have a 32-bit extension, you’ll have to load it from the 32-bit shell. Once
you launch, the window title bar will also display “(x86)” for the 32-bit versions, which
means you can always see which one you’re using.
TIP We recommend that you pin PowerShell to your taskbar. It makes
access much quicker. Right-clicking the icon on the taskbar provides access
to PowerShell and ISE in addition to providing links to run as Administrator
for both hosts.
On computers that have User Account Control (UAC) enabled, you’ll need to be a bit
careful. If your PowerShell window title bar doesn’t say “Administrator,” you’re not
running PowerShell with Administrator authority.
WARNING Watch the top-left corner of the host as it starts. It will say “Admin-
istrator: Windows PowerShell” or “Administrator: Windows PowerShell ISE”
during at least some of the startup period. Some of us, like Richard, modify
the title bar to display the path to the current working directory so the title
bar won’t show “Administrator” once the profile has finished executing.
10 CHAPTER 2 PowerShell hosts
If you’re not running as an Administrator, some tasks may fail with an “Access Denied”
error. For example, you can only access some WMI classes when you’re using Power-
Shell with the elevated privileges supplied by running as Administrator. If your title
bar doesn’t say “Administrator,” and you need to be an Administrator to do what
you’re doing, close the shell. Reopen it by right-clicking one of the Start menu short-
cuts and selecting Run as Administrator from the context menu. That’ll get you a win-
dow title bar like the one shown in figure 2.1, which is what you want. In Windows 8,
either right-click the taskbar shortcut or right-click the title on the Start screen to
access the option Run as Administrator.
It’s always worth taking a moment to verify whether your session is elevated before
continuing with your work. The PowerShell console is the simpler of the two available
hosts, which is why we’ll consider it before ISE.
2.2 The console
Most people’s first impression of PowerShell is the Microsoft-supplied console, shown
in figure 2.2. This console is built around an older piece of console software that’s
built into Windows—the same one used for the old Cmd.exe shell. Although Power-
Shell’s programmers tweaked the console’s initial appearance—it has a blue back-
ground rather than black, for example—it’s still the same piece of software that’s
been more or less unchanged since the early 1990s. As a result, it has a few limita-
tions. For example, it can’t properly display double-byte character set (DBCS) lan-
guages, making it difficult to use with Asian languages that require a larger character
set. The console also has primitive copy-and-paste functionality, along with fairly sim-
plistic editing capabilities.
You may wonder then, why use the console? If you’ve ever used a command-line
shell before, even one in a Unix or Linux environment, the console looks and feels
familiar. That’s the main reason. If you’re using Server Core, then the console is your
only choice, because the ISE won’t run on Server Core.
Figure 2.1 An elevated PowerShell session from Windows 8. Notice the Administrator label in
the caption.
11
The console
NOTE “Server Core” is a term that originated in Windows Server 2008. In
Windows Server 2012, “Server Core” is the default server installation that
doesn’t have the “Server Graphical Shell” feature installed. PowerShell wasn’t
available on the Windows Server 2008 version of Server Core, but it’s available
in Windows Server 2008 R2 and later.
Within the console, you can use a few tricks to make it a bit easier to work with:
■ Pressing the up and down arrows on your keyboard will cycle through the com-
mand history buffer, enabling you to recall previous commands, edit them, and
run them again.
■ Pressing F7 will display the command history buffer in a pop-up window. Use
the up and down arrow keys to select a previous command, and then either
press Enter to rerun the command or press the right arrow key to display the
command for editing.
■ Use your mouse to highlight blocks of text by left-clicking and dragging. Then,
press Enter to copy that block of text to the Windows clipboard. Quick Edit
Mode must be enabled in the console’s properties for this to work.
■ Right-click to paste the Windows clipboard contents into the console.
■ Use the Tab key to complete the PowerShell cmdlet, function, and parameter
names. In PowerShell v3, variable names can also be completed in this way.
You can also do a few things to make the console more comfortable for yourself. Click
the control box, which is at the top-left corner of the console window, and select Prop-
erties. You’ll want to make a few adjustments in this dialog box:
■ On the Options tab, you can increase the command history buffer. A bigger
buffer takes more memory but preserves more of the commands you’ve run,
allowing you to recall them and run them again more easily.
Figure 2.2 The Windows PowerShell console from Windows 8
12 CHAPTER 2 PowerShell hosts
■ On the Colors tab, choose text and background colors you’re comfortable reading.
■ On the Font tab, select a font face and size you like. This is important: You want
to be sure you can easily distinguish between the single quote and backtick
characters, between parentheses and curly brackets, and between single and
double quotes. Distinguishing these characters isn’t always easy to do using the
default font. The backtick and single quote confusion is particularly annoying.
NOTE On a U.S. keyboard, the backtick character is located on the upper-left
key, under the Esc key. It shares space with the tilde (~) character. It’s also
referred to as a “grave accent mark.” On non-U.S. keyboards, you may find it
in a different location.
■ On the Layout tab, make sure both Width settings are the same. The bottom one
controls the physical window size, whereas the top one controls the logical width of
the window. When they’re both the same, you won’t have a horizontal scrollbar. If
the upper “screen buffer” width is larger than the “window size,” you’ll have a hori-
zontal scrollbar. That means viewing much of PowerShell’s output will require hor-
izontal scrolling, which can become cumbersome and annoying to work with.
As you’re customizing your console window, take a moment to make sure it can dis-
play all the characters from the character set with which you work. If any characters
aren’t displaying properly, you may want to switch to the PowerShell ISE instead. Its
ability to use TrueType fonts and to display DBCS languages makes it a real advantage.
2.3 The PowerShell ISE
The PowerShell Integrated Scripting Environment, or ISE (usually pronounced “aye
ess eee,” not “ice”), was created to offer a better script-editing experience than Win-
dows Notepad, as well as provide a console experience that supports the use of DBCS
languages and TrueType fonts. In general, the ISE works similarly to the console host,
with a few exceptions:
■ The ISE can maintain several PowerShell runspaces in a single window by placing
each onto a separate tab. Each runspace is an instance of PowerShell, much like
opening multiple console windows.
■ The ISE can have multiple PowerShell scripts open simultaneously. Each is avail-
able through a separate tab.
■ The ISE displays graphical dialog boxes for many prompts and messages, rather
than displaying them on a command line as text.
■ The ISE doesn’t support transcripts, which we’ll describe later in this chapter.
■ You can change the font, starting size, and color schemes by selecting Tools
from the menu and then selecting the appropriate options. To adjust the text
display size, use the slider at the bottom right of the ISE window.
NOTE Server operating systems don’t have the ISE installed by default. If you
need it, you can install it using Server Manager like any other Windows feature.
13
The PowerShell ISE
You can also use PowerShell to install ISE on servers. The command syntax is
Add-WindowsFeature -Name PowerShell-ISE.
The ISE supports two basic layouts, which are controlled by the three buttons on its
toolbar. The default layout, shown in figure 2.3, uses two vertically stacked panes.
The top pane is the script editor, and the bottom pane is where you can interac-
tively type commands and receive output. In PowerShell v3, combining the interactive
and output panes effectively duplicates the PowerShell console.
Clicking the second layout button in the toolbar gives you the layout shown in fig-
ure 2.4, where the script editor takes up one side and the console takes up the other side.
Finally, the last button switches to a full-screen editor, which is useful if you’re
working on a long script. In some views, you’ll notice that the script pane has a little
blue arrow in the top-right corner. This can be used to hide or expose the script pane.
The other toolbar buttons, labeled in figure 2.5, provide access to the majority of
the ISE’s functions. You’ll also find additional options on the menu. The File, Edit,
and View menus are self-explanatory, and we’ll discuss the Debug menu when we
come to the topic of debugging in chapter 31.
Let’s try something: In the ISE, select New PowerShell Tab from the File menu.
(You’ll also see a Remote PowerShell Tab option. We’ll discuss that in chapter 10 on
Remoting.) What pops up is a whole new instance of PowerShell, called a runspace,
which we mentioned earlier. Each tab has its own set of script file tabs, with each file
tab representing a single script file. Each PowerShell tab also has its own output area
Figure 2.3 The default ISE layout uses two vertically stacked panes.
14 CHAPTER 2 PowerShell hosts
Figure 2.4 The split view gives you more room to edit a script.
Figure 2.5 Getting to know the ISE toolbar can save you time when performing common tasks.
Discovering Diverse Content Through
Random Scribd Documents
Even Watch the Dog was happy. He was lying at the foot of the
tree, with his nose on his paws as though he expected to stay there
all day, and wagging his tail.
But Louie Thomson, perched on one of its branches in the cold
wind, was very unhappy. Whenever he moved Watch would raise the
hair all along his back and growl, and the Red Cow would roll her
scary eyes at him. “Hey, Tommy!” he called. “Drive off those brutes
and let me come down!”
“No, I won’t,” said Tommy. “This is two times you’ve cheated me.
You cheated me with that old trap, and now you tried to come over
here into my very own woods and catch my very own Beasts. That’s
stealing. I’m going to let them watch you while I go up to the house
and get my father to come for you.”
Of course not one of the Woodsfolk knew what he meant. But
they knew he was very angry.
“Oh, please, please don’t do that!” begged Louie. “I’ll promise
never to set foot in your woods again. Honest, cross my heart and
hope to die, I will! Please let me go this time.”
Nibble sat straight up and listened hard. For Louie sounded just
like Chatter Squirrel the night of the Terrible Storm when he was so
terribly afraid. “My whiskers, but isn’t Tommy wonderful,” he
breathed to Watch. “You and the Red Cow can scare that Man when
you can reach him, but Tommy scares him without doing anything.”
And he came close up to Tommy’s tall rubber boots and cocked his
head on one side, trying to see how Tommy did it.
“I know you’ll promise,” Tommy was saying, “and you’ll keep it,
too, or else I’ll know about it.” He just meant he and Watch would
find Louie’s footprints.
But Louie saw that rabbit sitting by Tommy and looking exactly as
though he were talking to him.
“And if you want your traps,” Tommy went on, “you’ll have to get
that muskrat to find them.” He just meant he’d thrown them into the
pond.
But Louie Thomson didn’t know what to think of that. He guessed
perhaps he’d better leave Tommy Peele and his wild things very
much alone.
CHAPTER V
NIBBLE TELLS ONE SECRET AND HEARS ANOTHER
Now when Tommy Peele followed Watch back to the woods it was
because he thought the old dog was chasing Nibble Rabbit. Then he
made up his mind Nibble had warned Watch about that bad Louie
Thomson. He never dreamed Nibble had whispered a secret that
belonged to the Red Cow. So as soon as he’d made Louie promise to
behave, he whistled to Watch and began to lead the Red Cow away
so Louie could climb down.
Well, right then the Red Cow remembered that secret she had to
show him. So she insisted on leading him.
She fairly galloped around the end of the thicket, with Tommy
running after her in his tall rubber boots and Watch bounding after
him. But Nibble took a short cut through his tunnel. And he met
Doctor Muskrat coming to meet him.
“Climp, clump, climp, clump!” went a sound outside.
“What’s that?” asked Doctor Muskrat.
Nibble peered along the ground. And he could see Louie
Thomson’s boots moving very fast. “It’s that Man,” he exclaimed.
“He’s running like Silvertip the Fox did when the Red Cow took after
him.”
“Fine!” chuckled Doctor Muskrat. “He’ll never bring his wicked
jaws back here again. And we can thank Tommy Peele for that.”
Then there was another sound. “What’s that?” asked Nibble. And
Doctor Muskrat laughed. For it was Tommy Peele squealing with
surprise because he’d found the secret that belonged to the Red
Cow. “A calf! Oh, the cute little thing!”
The Red Cow walked around and around the
trunk of that big tree roaring at him.
So Nibble and Doctor Muskrat both crept back down the tunnel to
watch what was going on. The calf raised his head and looked at
Tommy; then he got up on his shaky legs and sniffed at him.
Because Tommy was a strange Beast with a strange smell and even
a baby knows enough to be careful about strange things. But when
he touched his little turned-up nose to the hand Tommy held out to
him he smelled his mother. You know Tommy had been stroking her.
So the foolish little rascal put out his little pink tongue, trying to lick
Tommy’s fingers. And wasn’t his mother pleased because they were
friends the very first thing!
Watch led the way, and Tommy walked beside the Red Cow and
helped to steer her wobbly-legged calf all the way up to the barn.
And the baby kept trying to kick up his silly little heels the way
Nibble used to when he felt playful. And he just would run splash
into all the puddles, and bunt and wriggle when they caught him.
The Red Cow kept getting prouder and prouder every step, but even
she was glad when they got safely home with him.
Nibble went with them as far as the Pasture. Doctor Muskrat was
enjoying a nice sweet flag-root (the first one he’d dug that spring)
when Nibble came loping back again. And he was the messiest
rabbit you ever heard of. And so cross and disgusted!
“That bad baby!” he complained, beginning to clean the mud
spots off his white shirt front. “He wouldn’t do anything I told him
to. And then, the very first time I wasn’t looking, he danced in a
puddle and splashed it all over me. From whiskers to—” he craned
his neck about to look—“to tail! He all but drowned me!”
“You don’t have to tell me that,” said Doctor Muskrat, and his fat
sides were shaking with laughter. “I’ve eyes to see with. You’re as
wet as ever you were when I fished you out of that pond there.” For
you remember how Nibble tumbled right into the water he was so
frightened the first time he ever saw the kind old muskrat.
“And then,” Nibble went on indignantly, “the impudent little scamp
sniffed his little turned-up nose at me because I was spluttering.”
“You can’t expect a calf to be born with manners, can you?”
soothed Doctor Muskrat, “’specially if it belongs to the Red Cow. But,
as I told her, that’s the most remarkable youngst——” He flattened
his ears, ready to dive, for a shadow came swooping down and he
was expecting the Marsh Hawk back any day.
But it was only Chaik the Jay. “Hello,” he piped. “Who was she
and what did you tell her?” And he pounced on an acorn that was
half-buried in the ground.
“The Red Cow,” answered Doctor Muskrat, “has a little new calf
who’s the most remarkable youngster I’ve ever seen.” And he was
going to tell Chaik all about it, only——
Didn’t Nibble Rabbit just interrupt and tell it all himself? Just
didn’t he? He was that puffed up because he was the first one to see
it that he couldn’t wait. He described, how bright its little eyes were,
and how it wriggled its tail like Chatter Squirrel does when he’s in a
temper, and—everything there was to tell about that Red Cow’s red
baby with the white star in his forehead and the turned-up nose.
And all the time Nibble was forgetting to clean his fur. And the
mud spots showed worse than ever as the wind dried them. But
Nibble was too busy talking about that very same bad little Beast
who had splashed them on him.
Chaik was preening and tucking in his feathers every once in a
while. He didn’t have his new spring coat yet, so he was very
particular over his old one. Presently he noticed Nibble. “By the
Worm in the Acorn, Rabbit, what’s happened to you?” he wanted to
know.
Do you think Nibble would tell on that Red Cow’s bad baby? Not
at all. He just said, “Oh, I wasn’t looking—you don’t know what the
walking is this spring.” Then he got very busy with his mud spots
and Chaik flew away.
“Hm,” giggled the doctor. “What do you really think of the Red
Cow’s calf, what you told me about it or what you told Chaik?”
“I mean,” said Nibble shamefacedly, “that I’m going up to see it
to-morrow morning.” And off he hopped to his bed.
He woke up early, early, before the darkest night had begun to
melt into the gray of dawn. He yawned sleepily and rolled over. My,
but that hole of his was warm and comfortable! Suddenly he jumped
up and began to scrub his face with his paws.
In about three minutes he was down by the pond, thumping for
Doctor Muskrat. And weren’t the doctor’s eyes all sleepy when he
poked his head out of the water? “Ouf,” he shivered, “what do you
want at this hour of the night? Spear me with an icicle, but this pond
is cold!” (If one of the Woodsfolk is found frozen to death the saying
is that he’s been speared by an icicle.)
“Come along,” said Nibble. “I’m going up to the barn to see the
Red Cow and her bad baby.”
“What do you take me for?” snorted the old doctor. “Don’t you
forget that Silvertip the Fox is living there! Gimlet the Woodpecker
said so. I can’t run like you can and there isn’t any water for me to
dive into.”
“I forgot,” apologized Nibble.
“Well, you just be careful,” warned the wise old beast, “and you
come straight back and tell me about him.”
So off went Nibble, creeping about among the puddles. He dove
into the Brushpile for a minute because he heard two birds talking.
But they were only little downy Mr. and Mrs. Screech Owl, smaller
than Bobby Robin. “I tell you it’s too early for nesting,” one was
saying.
“Not if Silvertip keeps on leaving all that nice food for us in the
fence corner,” insisted the other. “He scarcely eats half of what he
catches, and chickens are the best eating in the world for our
owlets. We wouldn’t have to do any hunting.”
“So,” said Nibble to himself, “Gimlet was right. Silvertip’s catching
Tommy Peele’s chickens.”
He sniffed carefully about the haystack and, sure enough, there
was a nice nest that smelled of Silvertip—it’s almost the same smell
as the seeds of the “cranes-bill,” as the Woodsfolk call wild
geranium. It was empty, so Nibble cocked an ear at the chicken
coop. Sure enough, there was a tiny rustling in the straw. As he sat
there listening he heard the scared shout of a pullet, “Squa-awk!
Squa-a—” and that was all. Silvertip had throttled her. Bounce! Down
he came from the perch and slam! Out he slipped through the little
back door his snoopy nose had learned how to open. But Nibble
didn’t dare call Watch for fear Silvertip would hear him.
Silvertip trotted past with the poor chicken
hanging from his jaws.
CHAPTER VI
A GAME OF TAG IN TOMMY’S BARN
You know about Nibble Rabbit. First he’s scared and then he’s
curious. He was scared when he heard Silvertip catch the pullet. And
he was still more scared when Silvertip trotted past in the mist,
splashing softly in the puddles, with the poor chicken hanging from
his jaws. But when Silvertip suddenly stopped and sniffed Nibble’s
own footprints by the haystack, he was the scaredest little rabbit in
all the fields and woods and the barnyard, too.
Just the same he could see Silvertip say to himself, “It’s too wet to
follow that trail. I’ll keep an eye out for bunnies around here as well
as birds.”
And Nibble said to his own self, “Bunny, that fox will have to do
some looking.” Then Silvertip picked up the chicken and trotted on.
Of course Nibble took a long breath when he had gone. That gave
him time to grow curious. “I wonder which fence-corner those
greedy little Screech Owls said he hid his food in?” he thought.
“Watch would like to know.” So he peeked around the end of the
stack and listened. Silvertip was away out of sight in the mist, but
his feet went splashing off to the very corner of the Broad Field,
where he used to sleep under some elderberry bushes. Yes, and
sometimes he’d catch the birds who came there for berries. Oh, that
Silvertip was certainly clever.
“Now,” Nibble thought, “it’s safe for me to hunt for the Red Cow.”
She wasn’t in the milking barn, but he could hear her baby, not very
far away, calling his mother to get up and give him his breakfast.
And the more he listened to that naughty little calf the more he
wanted to see it again. So he crept down the line of scary, switchy
tails, past the very last one. Then he came to a narrow lane, all
sprinkled with dried clover-leaves. Pretty soon he had to squeeze
under a door into another part of the barn. It was much brighter
than the milking barn, because there was a hole in the wall at the
far end. There were three box stalls, and he could hear the little calf
in the last one.
He hopped up on a bale of straw and ran along the top of the
partition until he could look in and see him. There that naughty little
beast had got tired of calling his mother and bunting her, so now he
was trying to kick her. And Nibble thought he was cunninger than
ever.
Of course the Red Cow was pleased to see him, and full of talk.
But Nibble was getting curious again. After a while he said, “Red
Cow, I can see the trees moving outside, but there isn’t any wind in
here. Why is that?”
“Why, I never thought about it,” said the Red Cow. You remember
she was always a little bit stupid.
“I’m going to find out,” said Nibble. He hopped carefully along the
partition to the window. And if ever a rabbit looked foolish, it was
Nibble when he snubbed his twitchy nose against it. He was puzzled.
None of the Woodsfolk could imagine such a thing as window glass.
“What is it?” asked the Red Cow, wagging her big ears.
“Ice,” guessed Nibble. “No, it’s not, either.” He was trying to taste
it with his licky little tongue that he uses to wash his shirt front. “It
doesn’t taste like the drops that freeze into my fur and it isn’t wet.
But it’s cold——”
And right then he learned some more about it. For you know
Silvertip had seen the bunny’s footprints. “Chickens are all right,”
thought the bad fox to himself as he trotted along, “but I’d a great
deal rather have a nice tasty mouthful of rabbit.” So he hid the pullet
and came galloping back to find Nibble.
It wasn’t long before he saw the bunny’s trail going into the door
of the milking barn, and he could smell plainly on the dry wood floor
exactly where Nibble had gone. So Silvertip went sniffing quietly
down the long aisle behind the row of cows. But they smelled him.
“Help! Watch! Wolves! Wolves! Help!” they bawled. And they all tried
to kick him.
Now Silvertip was afraid to run out past their heels, so he had to
follow Nibble’s trail under the door into the barn, where the box
stalls were. And there he saw Nibble, perched on top of the
partition, sniffing at the window with his back turned.
Up jumped Silvertip on to the straw bale. Down jumped Nibble
into the stall beside the Red Cow. “Arh,” whimpered Silvertip
excitedly, and jumped after him.
You never heard such a commotion. For the Red Cow began to
roar and aim her horns at the fox. And Silvertip had to do some
lively dodging. He’d just managed to scramble back on the partition
when Watch came squeezing under the door. There wasn’t another
place for the fox to turn so he ran straight for the window.
“Wouw!” he whimpered as he hit it. But it was too late to stop.
“Crash!” he went right through it and landed plump on the floor of a
wagon that stood beneath it. Then he went galloping off to the
woods as fast as he could go, holding up first one foot and then the
other, for he couldn’t make up his mind where he was hurt the most.
And his nose felt as if a bee had lit on it, and his eyes were so
bunged up he could hardly see where he was going, and he had a
new slit in the ear Mrs. Hooter had nipped—he was pretty badly
damaged. And he was grinding his teeth and blaming poor Nibble
Rabbit for every bit of it. For no one who thinks himself as clever as
Silvertip can get into trouble without finding some way to think
somebody else made him do it.
“Aourgh!” barked Watch excitedly. And then of course Nibble knew
he was perfectly safe, and he wanted to come out from under the
Red Cow’s manger, where he had hidden, to see what was
happening. But the naughty little calf was so excited he was dancing
around and bunting at everything in sight. His mother had to give
him some more breakfast before he’d stand still a single minute.
There was Nibble, perched on top of the
partition.
By that time Silvertip was away off down the Pasture and Watch
had squeezed under the door again. He was bound to catch that fox,
but he knew more than to go jumping through windows after him.
So Nibble just hopped up on the manger and from there onto the
high partition and stretched out his inquisitive nose where the glass
had been. There wasn’t much left for him to snub it against, I can
tell you. And the wind blew through it so hard that it laid his ears flat
back.
“What is it?” demanded the Red Cow. She was learning to be
curious, too, and that’s the first step to being wise and sensible.
“It’s awfully hard,” Nibble answered. “I can bite ice, but I can’t
bite this.”
Just then who should open the door but Tommy Peele with the
Red Cow’s breakfast.
Right away he saw the glass was broken. But he wasn’t angry at
all. He just said, “Did you do that?” But he picked up every bit that
had fallen inside so folks wouldn’t cut their feet on it, and then he
went around to pick up what was outside, too. And he found some
blood and a big tuft of Silvertip’s hair on the wagon-box.
“Phew!” he whistled. “Bunny, this fur isn’t any of yours—nor that
footprint, either! You just wait until school is out and Watch and I’ll
just see about this!”
He hadn’t any time to do it then. For he had to stuff the Red
Cow’s manger full of hay and hurry fast to get to the schoolhouse
before the bell rang.
“Have some, Nibble,” she lowed politely. And the bunny didn’t
need a second invitation. His twitchy nose had been wiggling pretty
fast from the first minute he smelled that delicious clover.
CHAPTER VII
THE WHITE COW BEGINS A STORY
If the smell of that delicious hay in the Red Cow’s manger made
Nibble’s nose go fast, the taste of it made his hungry little jaws go
still faster. And the Red Cow was just about as busy as he was. Her
big teeth wouldn’t move quite so quickly, but she could take bigger
bites to make up for lost time.
They were still eating when he heard a loud snort just outside. So
he jumped up on the windowsill again to be sure who it was. “Hello,
Rabbit,” came the White Cow’s nice fluty voice as she saw his
whiskers in the window. “I told you you’d come back again.”
“Oh, the Red Cow’s got such a cunning calf in here I just have to
come,” he laughed.
“She has, has she?” mooed the White Cow. “I’d like to see it
myself.” She was a motherly old beast, so she really did love babies.
“Is it all right? That wolf who ran through the milking barns has
been around here—I can smell him. Calves are what they always
come for.”
“That was only Silvertip the Fox,” he chuckled. “He’s gone!”
Still the White Cow kept shaking her head and snorting. “He’s no
business here. He’s a wolf, and it’s plain against the compact.”
“What compact, please, Madame Snowflake?” lowed the Red Cow.
“Why, the compact between Cows and Man,” she answered. “You
know Man used to hunt us. It must have been dreadful, for one man
is worse than a whole pack of wolves-”
“Exactly what Doctor Muskrat says!” exclaimed Nibble.
“Well, it’s true,” she asserted. “Cows are all right so long as they
keep all together. But you can’t have little new wobbly babies in a
herd because we’re so near-sighted someone would be sure to step
on them. So the mothers used to go off and hide them until they
grew strong enough not to let themselves get stepped on. And the
wolves and the men would watch out for them. No matter how
careful the cows were someone would be sure to find them. Long
before they came, the mothers would get all scary and unhappy just
thinking about it.”
“I felt just that way!” gasped the Red Cow. “Didn’t I, Nibble?”
“Well, after a long time Man made a compact with the cows. He
promised that if they’d live with him and give him milk and plough
his fields and let him take the meat of certain ones, not the young
heifers or the mothers, he’d keep the wolves away from them.”
“How did that happen?” asked Nibble excitedly, for he guessed it
was one of those tales of the First-Off Beginning of Things.
And sure enough, the White Cow began, “Well, as I said, both
Man and wolves hunted the cows in the First-Off Beginning. That
was bad enough. But when Man made friends with the dogs, who
were really wolves, it was worse yet. They both knew all the tricks
between them.
“There was a river wandering through the plain where the cows
used to feed, and it had a rocky island standing up in the middle of
it. The island was hollow as a cup and full of brush and grass, and
there was only one crack in the rocks where a cow could just
squeeze through to get into it. It was a secret among the cows, who
only went there to raise their calves, and they were careful to walk a
long way in the water to hide their trails before they crossed over to
it. So the wolves would never have found it. But a man did.
“He was hunting cows. So were a pack of wolves, and they saw
he had only one dog, so they decided to hunt him instead. They say
a man is very good eating. So he ran for the island. Because he
knew if he could climb high up on the tall rocks they couldn’t climb
up after him. He had to take his dog by the scruff of the neck to
help him. And of course when he got up high he could see
everything—the two cows who were grazing in the middle of the
island and the narrow passage between the rocks, and the wolves
running around and around looking for a place where they could get
in.
“The cows couldn’t see the wolves, but they could hear them. So
one of them, who was an old cow and very wise, galloped over to
the passage. And when the wolves got there she was stopping the
way with her sharp horns.
“I don’t know how long she could have stayed there, for there
were a great many wolves and only one cow, but the man was wiser
yet. He saw a big tippy boulder that he could roll down to block the
passage so nobody could possibly get in. And he gave it a big shove.
Smash, it went down right in the middle of the wolves! It killed the
leader and another wolf, and the rest got scared and ran away.
“So did the cow, for the man’s dog started right after her. But the
man called him back. ‘Come here!’ he called. ‘Stop that, you foolish
thing. The wolves would have picked our bones if she hadn’t helped
us. That’s one cow you can never kill.’
“The dog came back with his tail between his legs, grumbling to
himself. ‘This is very queer. It’s the first time in all my life I was told
not to kill anything.’ And of course the cow heard him. And it set her
thinking.”
CHAPTER VIII
HOW THE MAN’S WIFE MADE THE COMPACT WITH THE COWS
The White Cow stopped talking quite as though she had finished
her story. But Nibble Rabbit and the Red Cow, who were listening
with all their ears, both broke out: “Please, Mrs. Snowflake, you
haven’t said a word yet about the compact!”
“Pickery thistles!” she exclaimed. “So I haven’t. I was just thinking
about it instead. Well, the man was in the middle of that little hollow
island with the high rocks all around it, and so were the cows. The
dog was growling because he couldn’t kill the cow, and the cow was
wondering why the man wouldn’t let him. But most of all she was
wondering how quickly she and her calf would starve because that
stone blocked up the passage.
“The man was thinking that, too. For the cow had saved his life by
keeping out the wolves; that made him in debt to her. And if a man
was careless about his debts he was sure to be dreadfully unlucky.
Either he had to roll away that stone so the cow could go over to the
plains to graze—and he knew he couldn’t do that—or he had to bring
the grass to her.
“Bright and early next morning he went to bring the grass to feed
that cow. He found it was lots of trouble, especially since he didn’t
have his wife there to help him. So he decided to bring her.
“He told her how nice and safe it was in the middle of that rocky
island until she got quite delighted at the idea of living there. So she
packed their belongings on her back, slung their baby in front of her,
and started out. She waded the stream all right, but she stopped at
the big rock which blocked up the passage.
“‘I won’t stay here at all unless you take that out of there,’ she
said. ‘It’s too inconvenient.’
“So of course he just had to. And when it comes right down to
‘having to’ a man can do almost anything. But he had a terrible time.
He heaved and clawed and shoved and rolled until his fingers and
arms were sore. Then he picked up a stick, because it was easier to
handle—and he learned how to pry that stone out of the passage.
“In walked his wife and began to settle their new home. Out
walked the cows, and over they went to the plain to pick their own
grass, but they left their calves hidden on the island. So, after they
had finished feeding, back they came.
“Then the man took his stick and pried the rock into the passage
again for fear the wolves would come back. And his wife stared at
the cows and the cows stared at his wife, but still they didn’t make
any compact.”
Nibble Rabbit and the Red Cow were both fairly stamping their
feet with impatience because the White Cow wouldn’t hurry right
along with her story. But she brought a big wad of cud all the way
up her long neck and stood there chewing it while she thought
things over. Finally she swallowed it and went on.
“I told you the man learned to use the great stone for a gate to
the narrow passageway where the cows squeezed through. But I
didn’t tell you how angry the wolves were about that.
“They were simply raging. Night after night they gnashed their
jaws and howled around those rocks, but their claws wouldn’t climb
them. And the man’s dog would sit up on top and shout insults at
them. And the two cows would snuggle together in the brush with
their calves between them and say, ‘Those wolves would have eaten
us long ago if the man hadn’t been here.’
“They got very used to the man and his family. They didn’t walk
’way round his fire any more, or make eyes at his wife, and the
calves got very friendly with his baby. But his wife used to look hard
at them. ‘It’s all very well to take care of the cow who saved your
life,’ she’d say to the man, ‘but how about that other one?’
“‘Well, what about her?’ he’d answer. ‘She isn’t any trouble.’
“‘She ought to pay for being taken care of,’ insisted his wife. ‘It’s
all very well for this year, but next year these calves will be grown up
and there will be new ones and we’ll be all cluttered up with cattle.’
“She thought and thought. At last she caught up her biggest
clamshell and walked down into the thicket where the cows stood.
And the dog went with her. ‘Old Cow,’ she said, ‘you can live with us
for ever and ever because you stopped the passageway with your
horns when the wolves were trying to get in to kill my husband.
Young Cow, you will have to pay something if you’re going to live
with us.’ And with that she tried to milk the young cow into her
clamshell.
“The young cow didn’t like it a little bit. But she was afraid of the
dog, and besides the old cow argued, ‘You have milk to spare, and
you’ll never have any place as safe as this. Let me talk to her.’
“So the young cow gave in and let herself be milked. But the old
one said to the woman: ‘We’ll stay with you and give you milk so
long as you see we get food and water and protect us from the
wolves. But the minute you don’t we’ll go off and be wild again, and
you’ll be no better off than you were before.’
“‘Agreed,’ said the woman. ‘The dog will be our witness.’
“So that was the beginning of the compact. The cows settled
down to live with the man and his family. But after the woman was
gone the wise old cow said comfortably, ‘It’s spring now. She doesn’t
think how much trouble it will be to feed us through the winter.’”
“Wasn’t that old cow clever!” exclaimed Nibble admiringly.
The White Cow snorted. “She was wise. But that woman was
wiser. She knew that if she waited long enough there would be cattle
on that island who hadn’t any milk, so she and the man could
bargain some more with them. They had to carry loads and pull
ploughs; they even had to let the man kill certain ones. They didn’t
like that a little bit, but the wise old cow argued, ‘It’s better than
being hunted by both wolves and men.’ So they finally gave in. It
was really a good bargain for us,” finished the White Cow
thoughtfully, “but it was a better one for the man. After he learned
to build barns as safe as that island he gave up hunting.”
CHAPTER IX
HOW A BUNNY UNDERTOOK TO HUNT A FOX
Madame snowflake swished her tail thoughtfully for a moment;
then she went back to chewing her cud as a sign that her story was
all done.
“My horns!” exclaimed the Red Cow. “That’s awfully interesting.”
“Yes,” drawled the story-teller. “But can’t you see how worrisome
it is? If Tommy Peele lets wolves go galloping through this barn we’ll
have to go wild again. It’s in the compact. That’s what I’ve been
trying to explain.”
“Noo-oo-oo,” the Red Cow moaned. “I don’t want to go wild. I
won’t go wild again. I’ve been wild once, and I like being Tommy
Peele’s tame cow ever so much better.”
“Nonsense!” interrupted Nibble Rabbit, sitting up very straight. “It
hasn’t anything at all to do with you cows. Silvertip’s no more of a
wolf than Watch is. Besides, I’m the only one he was chasing. He
won’t come back again unless I do, and I won’t come until there
isn’t any Silvertip to chase me.”
“Hoo-oo,” teased the White Cow. “What can you do to Silvertip?”
“Wait and see,” said Nibble. And off he set. But as he ran he said
to himself, “Silvertip’s very big and clever—whatever can I do to
him?”
For a while he was just about the most thoughtful bunny that ever
flopped an ear. He’d made the White Cow a great big promise, one
no grownup rabbit would ever have thought of.
And he had to have help about it. He was pretty glad, I can tell
you, when he saw Watch scouting about the pasture with his nose to
the ground.
“Have you found where Silvertip went to?” Nibble asked when the
big dog stopped to speak with him.
“No,” said Watch in a discouraged tone. “There was a mist this
morning and it’s washed away all the scent. But what do you want of
Silvertip?”
“I’ve got to help you catch him,” murmured Nibble.
“You!” exclaimed Watch. “You must be as crazy as a chickadee!
Has any thing bitten you?” You know dogs are terribly afraid of being
bitten by a crazy beast—it makes them go mad, too.
“No. But—but I promised the White Cow that I wouldn’t come
back to the barn while Silvertip was alive to chase into it after me—
and I won’t stay away from the Red Cow’s baby for ever and ever.
Something’s got to happen to Silvertip.”
“I wouldn’t want him chasing me if I were you,” Watch agreed.
This sounded more sensible. “But I don’t see what the White Cow
has to do with it.”
“She says Silvertip is really a wolf,” Nibble explained, “and if
Tommy Peele lets wolves come right into his barn, whether it’s
calves or rabbits they’re hunting, the cows will have to go wild
again. That’s in the compact between cows and man in the First-Off
Beginning.”
“Wurr-r-r!” Watch growled thoughtfully. “So it is. But that’s my
trouble, and the cow’s and Tommy’s. It hasn’t anything to do with
you.”
Suddenly Nibble remembered something and quoted:
“By dusk and by dawn you shall travel alone.
And all troubles are yours excepting your own.
That’s my fortune. The stars told it to Doctor Muskrat the day I
left home.”
“I understand,” Watch nodded wisely. “Well, the trouble about all
this is that I can’t explain it to Tommy. And we need him. What can
you do to Silvertip—except give him a stomachache from eating too
much rabbit, eh?”
“I can see where he is and what he does. I know how he gets
into the chicken coop and where he hid the pullet he stole this
morning and the feathers from all the rest he’s been stealing.”
“How—when—where!” barked Watch excitedly. “We don’t have to
tell that to Tommy—we can show it to him. Quick, Nibble! How did
Silvertip get into the chicken coop? Tommy’ll be home from school
any minute.”
So Nibble took him around to the little back door. “That fox is
certainly clever,” sniffed Watch. “He’s gnawed the hook right off. I’ve
smelt him around here dozens of times, but I never thought of
looking inside of the coop for him.” Then he lifted it with his nose,
just as Silvertip had done, but he was too big to crawl in.
It was Nibble who squeezed through and took a hop on to the
soft straw of the chicken coop floor. Then he sat up to sniff around.
The hens were scratching busily, but the rooster was dozing off a full
crop on his perch. Nibble poked his nose into a box of feed and the
bird next to him went, “Cut, cut!” That woke the rooster. He opened
his eye and caught sight of Nibble’s whiskers.
“Er—er—err, I’m Chanticleer!” he crowed. “And you’re the rascal
who stole my beautiful young wife, Specklefeather, this morning!
You’re the one who took Stripedwing, the best setting hen ever a
rooster owned, and dear little red-wattled Minorca—and all the rest
who’ve been snatched from my perches. Your time has come! I’ll
show you——” and he flapped down and began to peck poor Nibble
and kick him with those long spurs roosters wear on their legs.
Nibble visits the chicken coop.
“Wait a minute, wait a minute!” Nibble cried. But the rooster
wouldn’t listen. Then a voice behind Nibble called, “Here, here,” and
he darted under the perches and squeezed into a dark nest beside a
hen.
“There,” she clucked. “That old bully never comes here. It isn’t
proper for a rooster to come into the nesting corner. Poor
Stripedwing. She used to set in here most of the time because he
was so cruel to her. And he killed our son because Minorca was in
love with him. I wish the fox had taken him.”
Nibble peeked out again and saw the rooster strutting around as
though he’d really done something grand, calling on the hens to
admire him. And now he could hear Watch shouting, “Come along,
Tommy—come quick!” In a minute more he was barking outside the
front door, and Tommy opened it.
“What’s the matter?” asked Tommy. Out hopped Nibble Rabbit.
“However did you get in here?” gasped the little boy. And with that
Nibble slipped through the little back door as neat as you please.
Maybe Tommy didn’t whistle! And maybe he wasn’t still more
surprised when he saw the hook all gnawed! But maybe he wasn’t
maddest of all when Nibble and Watch took him across the field to
Silvertip’s fence corner, all full of feathers, with poor dead
Specklefeather lying in the middle of it!
“The fox!” Tommy exclaimed. “Old chicken thief; he ought to be
hunted with a gun!”
“That’s all right,” Watch wagged his tail. “Now Tommy’ll find the
gun and a man to shoot it, but we’ll have to find Silvertip so they
can shoot him. I’ll sleep in the haystack and watch the barn, and
you see if he’s hidden in the woods.”
So Nibble cocked his own little puffy tail and laid back his ears and
scuttled through the cornfield. Because the first one he meant to ask
was Doctor Muskrat. And it didn’t take much thumping to wake the
doctor.
“My whiskers, but I’m glad to see you,” said the nice old beast as
soon as he got his nose out of the water. “I was afraid that fox had
really caught you. He came down here for a drink early this morning.
He was feeling pretty sick, but he said he wasn’t going to do another
thing until he’d pulled your long ears out by the roots and made a
meal of you.”
“Well, he doesn’t want to find me any more than I want to find
him,” said Nibble. And he told how Silvertip had followed him into
the barn and jumped smash through the window, and what trouble
that made for the cows, and the way he’d killed Tommy’s chickens,
and how angry Tommy was about it.
“Shoot him? I wish they would.” Doctor Muskrat agreed. “He’s the
worst beast in all the woods and fields, and we’ve plenty more to
look out for—Slyfoot the Mink and the Marsh Hawk are back, and
Grandpop Snapping Turtle is out again—but you’ll have to be mighty
careful. You dig yourself a root and stay hidden while I see what the
birds know about him.”
So Doctor Muskrat asked every bird who came down to drink if
he’d keep an eye out for Silvertip. That was a great many, too, for
whole clouds of them were coming north on every south wind. But
they were all so busy about courting and nesting it was three days
before Doctor Muskrat had any news. Late in the evening a
whippoorwill came dipping down like a great feathery moth and
called softly: “Doctor Muskrat!” Then he perched on the doctor’s
house and whispered: “Silvertip’s living in the hollow log that
shadows my last year’s nest. He’s still too sick to hunt anything but
frogs and tadpoles and the eggs of us poor ground birds, but the
minute he can gallop he’s going to get that rabbit. He lies there
growling and swearing about him.”
Nibble couldn’t hear what the whippoorwill said. And that was
lucky, because he was lying very still in the Quail’s Thicket with those
screech owls perched right above him.
CHAPTER X
THE WICKED PLOT OF THE BAD LITTLE OWLS
As soon as the whippoorwill had finished whispering the news,
about where Silvertip was hiding, he flew off so quietly that even the
doctor couldn’t hear him. Then the wise old beast raised his queer,
thin call, almost like a whistle, to tell Nibble Rabbit he was wanted,
and swam quite as quietly to the place in the bulrushes by the pond
where they always met.
But no Nibble came. Nibble Rabbit was still hiding in the Quail’s
Thicket, listening to Mr. and Mrs. Screech Owl, who were perched
right above him.
“That bird’s telling him about Silvertip,” said one. “If it had been
any other bird in the woods he’d have spoken so we could overhear
him.”
“I wish he had,” said the other. “We’ve picked that last hen so
clean we’ll have to hunt for ourselves if we can’t find him. I wonder
what that muskrat wants of him. He’s been asking every bird who
came down to drink for the last three days. I heard Chaik the Jay
talking to Chewee the Chickadee about it just when I was going to
sleep this morning.”
“What did they say?” demanded Mrs. Screech Owl. The lady owl is
always the more thoughtful. They both live in trees. Silvertip never
bothers them.
“I didn’t understand,” said her mate. “Chaik was insisting that
they must all hunt hard for Silvertip. He said that it concerned every
good friend of Tommy Peele’s.”
“You pinfeathered idiot!” she exclaimed. “Why didn’t you tell me
that before? That explains why Tommy Peele and his dog were
sniffing about Silvertip’s fence corner. And that rabbit was with them.
He’s at the bottom of all this. Something’s wrong there. I never
knew a wild rabbit to be friends with a dog in all my life. If he’ll do
that he’ll do anything. Silvertip must be warned. We can’t let
anything happen to him. Besides, think how much he could do for us
if he felt grateful.”
“Grateful? Not much. A fox is never grateful. But he’d know we
were useful and that amounts to the same thing. I wonder why that
rabbit doesn’t answer Doctor Muskrat?” and Mr. Screech Owl flew
cautiously over the doctor’s house in the middle of the pond. Back
he came to where his wife was still thinking. “He must have meant
that call for the whippoorwill,” he said to his mate. “He’s gone to
bed.”
“We must get some friend who lives on the ground to keep watch
for us, too,” said the Lady Owl thoughtfully. “Only Silvertip has no
friends. He’ll eat anybody.”
“Excepting old Foul Fang the Rattlesnake,” said Mr. Screech Owl.
“We could buy Foul Fang’s service for a mouse a day. I’ll just do that,
and you go up to the house, not the barn, mind, and see if you can
get a word with that grandson of Ouphe the Rat who lives there.
Silvertip’s never hunted him. By the kitchen door—now flutter!” And
away they went.
But Nibble waited until he was perfectly sure they had gone
before he crept down to talk with Doctor Muskrat in the bulrushes.
And he was a pretty trembly little rabbit. He hopped very carefully,
gliding from shadow to shadow like a fieldmouse. And the doctor
never moved when Nibble Rabbit slipped in beside him; he was
listening to the stars as they danced in the pool just exactly the way
he had done the night they told him Nibble’s fortune. He was
muttering:
“Let him who is both young and wise
Beware the killer with lidless eyes.
“Yes, that’s all I can make out of it,” said the old doctor slowly.
“Now what does that mean, I wonder?”
Welcome to Our Bookstore - The Ultimate Destination for Book Lovers
Are you passionate about books and eager to explore new worlds of
knowledge? At our website, we offer a vast collection of books that
cater to every interest and age group. From classic literature to
specialized publications, self-help books, and children’s stories, we
have it all! Each book is a gateway to new adventures, helping you
expand your knowledge and nourish your soul
Experience Convenient and Enjoyable Book Shopping Our website is more
than just an online bookstore—it’s a bridge connecting readers to the
timeless values of culture and wisdom. With a sleek and user-friendly
interface and a smart search system, you can find your favorite books
quickly and easily. Enjoy special promotions, fast home delivery, and
a seamless shopping experience that saves you time and enhances your
love for reading.
Let us accompany you on the journey of exploring knowledge and
personal growth!
ebookgate.com

More Related Content

PDF
Windows Powershell Cookbook Second Edition Second Edition Lee Holmes
PDF
Eclipse In Action A Guide For Java Developers 1st Edition David Gallardo
PDF
Windows Powershell in Action 1st Edition Bruce G. Payette
PDF
[Ebooks PDF] download Ajax in Practice 1st Edition Dave Crane full chapters
PDF
Windows Powershell in Action 1st Edition Bruce G. Payette
PDF
Windows Powershell in Action 1st Edition Bruce G. Payette
PDF
ASP NET 4 0 in Practice Daniele Bochicchio
PDF
WebWork in Action In Action First Edition Patrick Lightbody
Windows Powershell Cookbook Second Edition Second Edition Lee Holmes
Eclipse In Action A Guide For Java Developers 1st Edition David Gallardo
Windows Powershell in Action 1st Edition Bruce G. Payette
[Ebooks PDF] download Ajax in Practice 1st Edition Dave Crane full chapters
Windows Powershell in Action 1st Edition Bruce G. Payette
Windows Powershell in Action 1st Edition Bruce G. Payette
ASP NET 4 0 in Practice Daniele Bochicchio
WebWork in Action In Action First Edition Patrick Lightbody

Similar to PowerShell in Depth An administrator s guide Don Jones (20)

PDF
Open Source ESBs in Action 1st Edition Tijs Rademakers
PDF
ASP NET MVC in Action 1st Edition Jeffrey Palermo
PDF
Open Source ESBs in Action 1st Edition Tijs Rademakers
PDF
WebWork in Action In Action First Edition Patrick Lightbody
PDF
ASP NET 4 0 in Practice Daniele Bochicchio
PDF
Open Source ESBs in Action 1st Edition Tijs Rademakers
PDF
C CLI in Action 1st Edition Nishant Sivakumar
PDF
Windows Store App Development C and XAML Pete Brown
PDF
WebWork in Action In Action First Edition Patrick Lightbody
PDF
JavaScript Application Design A Build First Approach 1st Edition Nicolas Beva...
PDF
Download full ebook of Azure in Action 1st Edition Chris Hay instant download...
PDF
C CLI in Action 1st Edition Nishant Sivakumar
PDF
Getting MEAN with Mongo Express Angular and Node 1st Edition Simon Holmes
PDF
Getting MEAN with Mongo Express Angular and Node 1st Edition Simon Holmes
PDF
React in Action 1st Edition Mark Tielens Thomas
PDF
ASP NET 4 0 in Practice Daniele Bochicchio
PDF
Open Source ESBs in Action 1st Edition Tijs Rademakers
PDF
Open Source ESBs in Action 1st Edition Tijs Rademakers
PDF
Ext JS in Action 1st Edition Jesus Garcia
PDF
JavaScript Application Design A Build First Approach 1st Edition Nicolas Beva...
Open Source ESBs in Action 1st Edition Tijs Rademakers
ASP NET MVC in Action 1st Edition Jeffrey Palermo
Open Source ESBs in Action 1st Edition Tijs Rademakers
WebWork in Action In Action First Edition Patrick Lightbody
ASP NET 4 0 in Practice Daniele Bochicchio
Open Source ESBs in Action 1st Edition Tijs Rademakers
C CLI in Action 1st Edition Nishant Sivakumar
Windows Store App Development C and XAML Pete Brown
WebWork in Action In Action First Edition Patrick Lightbody
JavaScript Application Design A Build First Approach 1st Edition Nicolas Beva...
Download full ebook of Azure in Action 1st Edition Chris Hay instant download...
C CLI in Action 1st Edition Nishant Sivakumar
Getting MEAN with Mongo Express Angular and Node 1st Edition Simon Holmes
Getting MEAN with Mongo Express Angular and Node 1st Edition Simon Holmes
React in Action 1st Edition Mark Tielens Thomas
ASP NET 4 0 in Practice Daniele Bochicchio
Open Source ESBs in Action 1st Edition Tijs Rademakers
Open Source ESBs in Action 1st Edition Tijs Rademakers
Ext JS in Action 1st Edition Jesus Garcia
JavaScript Application Design A Build First Approach 1st Edition Nicolas Beva...
Ad

Recently uploaded (20)

PPTX
Lesson notes of climatology university.
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PPTX
master seminar digital applications in india
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PPTX
Institutional Correction lecture only . . .
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PPTX
GDM (1) (1).pptx small presentation for students
PDF
RMMM.pdf make it easy to upload and study
PDF
Anesthesia in Laparoscopic Surgery in India
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PPTX
Cell Structure & Organelles in detailed.
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PDF
TR - Agricultural Crops Production NC III.pdf
PDF
Insiders guide to clinical Medicine.pdf
PDF
Complications of Minimal Access Surgery at WLH
PDF
Classroom Observation Tools for Teachers
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
Lesson notes of climatology university.
Pharmacology of Heart Failure /Pharmacotherapy of CHF
master seminar digital applications in india
102 student loan defaulters named and shamed – Is someone you know on the list?
Institutional Correction lecture only . . .
O5-L3 Freight Transport Ops (International) V1.pdf
Abdominal Access Techniques with Prof. Dr. R K Mishra
GDM (1) (1).pptx small presentation for students
RMMM.pdf make it easy to upload and study
Anesthesia in Laparoscopic Surgery in India
FourierSeries-QuestionsWithAnswers(Part-A).pdf
Cell Structure & Organelles in detailed.
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
human mycosis Human fungal infections are called human mycosis..pptx
TR - Agricultural Crops Production NC III.pdf
Insiders guide to clinical Medicine.pdf
Complications of Minimal Access Surgery at WLH
Classroom Observation Tools for Teachers
Supply Chain Operations Speaking Notes -ICLT Program
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
Ad

PowerShell in Depth An administrator s guide Don Jones

  • 1. PowerShell in Depth An administrator s guide Don Jones download https://ebookgate.com/product/powershell-in-depth-an- administrator-s-guide-don-jones/ Get Instant Ebook Downloads – Browse at https://ebookgate.com
  • 2. Get Your Digital Files Instantly: PDF, ePub, MOBI and More Quick Digital Downloads: PDF, ePub, MOBI and Other Formats Learn Windows PowerShell 3 in a Month of Lunches Second Edition Don Jones https://ebookgate.com/product/learn-windows-powershell-3-in-a- month-of-lunches-second-edition-don-jones/ Windows PowerShell 2 0 Administrators Pocket Consultant Administrator s Pocket Consultant 1st Edition William R. Stanek https://ebookgate.com/product/windows- powershell-2-0-administrators-pocket-consultant-administrator-s- pocket-consultant-1st-edition-william-r-stanek/ Wordpress and Ajax An In Depth Guide on Using Ajax With WordPress 2nd Edition Edition Ronald Huereca https://ebookgate.com/product/wordpress-and-ajax-an-in-depth- guide-on-using-ajax-with-wordpress-2nd-edition-edition-ronald- huereca/ Linux Mint System Administrator s Beginner s Guide 1st Edition Arturo Fernandez Montoro https://ebookgate.com/product/linux-mint-system-administrator-s- beginner-s-guide-1st-edition-arturo-fernandez-montoro-2/
  • 3. Linux Mint System Administrator s Beginner s Guide 1st Edition Arturo Fernandez Montoro https://ebookgate.com/product/linux-mint-system-administrator-s- beginner-s-guide-1st-edition-arturo-fernandez-montoro/ Dx Rx Gynecologic Cancer Jones and Bartlett Publishers Dx Rx Oncology Series 1st Edition Don S. Dizon https://ebookgate.com/product/dx-rx-gynecologic-cancer-jones-and- bartlett-publishers-dx-rx-oncology-series-1st-edition-don-s- dizon/ Maximum PC 2005 Buyer s Guide 1st Edition George Jones https://ebookgate.com/product/maximum-pc-2005-buyer-s-guide-1st- edition-george-jones/ Windows PowerShell Cookbook The Complete Guide to Scripting Microsoft s Command Shell Third Edition Lee Holmes https://ebookgate.com/product/windows-powershell-cookbook-the- complete-guide-to-scripting-microsoft-s-command-shell-third- edition-lee-holmes/ C In Depth 2nd Edition S.K. Srivastava https://ebookgate.com/product/c-in-depth-2nd-edition-s-k- srivastava/
  • 4. M A N N I N G Don Jones Richard Siddaway Jeffery Hicks An administrator’s guide Covers PowerShell 3.0
  • 7. PowerShell in Depth AN ADMINISTRATOR’S GUIDE DON JONES RICHARD SIDDAWAY JEFFERY HICKS M A N N I N G SHELTER ISLAND
  • 8. For online information and ordering of this and other Manning books, please visit www.manning.com. The publisher offers discounts on this book when ordered in quantity. For more information, please contact Special Sales Department Manning Publications Co. 20 Baldwin Road PO Box 261 Shelter Island, NY 11964 Email: orders@manning.com ©2013 by Manning Publications Co. All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form or by means electronic, mechanical, photocopying, or otherwise, without prior written permission of the publisher. Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in the book, and Manning Publications was aware of a trademark claim, the designations have been printed in initial caps or all caps. Recognizing the importance of preserving what has been written, it is Manning’s policy to have the books we publish printed on acid-free paper, and we exert our best efforts to that end. Recognizing also our responsibility to conserve the resources of our planet, Manning books are printed on paper that is at least 15 percent recycled and processed without the use of elemental chlorine. Manning Publications Co. Development editor: Cynthia Kane 20 Baldwin Road Copyeditor: Liz Welch PO Box 261 Technical proofreader: Aleksandar Nikolic Shelter Island, NY 11964 Proofreader: Linda Recktenwald Typesetter: Dennis Dalinnik Cover designer: Marija Tudor ISBN: 9781617290558 Printed in the United States of America 1 2 3 4 5 6 7 8 9 10 – MAL – 19 18 17 16 15 14 13
  • 9. v brief contents PART 1 POWERSHELL FUNDAMENTALS . .....................................1 1 ■ Introduction 3 2 ■ PowerShell hosts 7 3 ■ Using the PowerShell help system 17 4 ■ The basics of PowerShell syntax 29 5 ■ Working with PSSnapins and modules 39 6 ■ Operators 46 7 ■ Working with objects 60 8 ■ The PowerShell pipeline 93 9 ■ Formatting 111 PART 2 POWERSHELL MANAGEMENT ......................................127 10 ■ PowerShell Remoting 129 11 ■ Background jobs and scheduling 160 12 ■ Working with credentials 174 13 ■ Regular expressions 184 14 ■ Working with HTML and XML data 196
  • 10. BRIEF CONTENTS vi 15 ■ PSDrives and PSProviders 210 16 ■ Variables, arrays, hash tables, and scriptblocks 224 17 ■ PowerShell security 244 18 ■ Advanced PowerShell syntax 257 PART 3 POWERSHELL SCRIPTING AND AUTOMATION...............275 19 ■ PowerShell’s scripting language 277 20 ■ Basic scripts and functions 291 21 ■ Creating objects for output 301 22 ■ Scope 317 23 ■ PowerShell workflows 332 24 ■ Advanced syntax for scripts and functions 359 25 ■ Script modules and manifest modules 379 26 ■ Custom formatting views 391 27 ■ Custom type extensions 403 28 ■ Data language and internationalization 417 29 ■ Writing help 429 30 ■ Error handling techniques 435 31 ■ Debugging tools and techniques 447 32 ■ Functions that work like cmdlets 466 33 ■ Tips and tricks for creating reports 485 PART 4 ADVANCED POWERSHELL ...........................................495 34 ■ Working with the Component Object Model (COM) 497 35 ■ Working with .NET Framework objects 505 36 ■ Accessing databases 517 37 ■ Proxy functions 525 38 ■ Building a GUI 538 39 ■ WMI and CIM 557 40 ■ Best practices 584
  • 11. vii contents preface xxi acknowledgments xxiii about this book xxv about the authors xxvii about the cover illustration xxix PART 1 POWERSHELL FUNDAMENTALS. ..........................1 1 Introduction 3 1.1 Who this book is for 3 1.2 What this book will teach you 4 1.3 What this book won’t teach you 4 1.4 Where we drew the line 5 1.5 Beyond PowerShell 5 1.6 Ready? 6 2 PowerShell hosts 7 2.1 32-bit vs. 64-bit, and administrator vs. not 8 2.2 The console 10 2.3 The PowerShell ISE 12
  • 12. CONTENTS viii 2.4 Command history buffer vs. PowerShell’s history 15 2.5 Transcripts 16 2.6 Summary 16 3 Using the PowerShell help system 17 3.1 The help commands 17 3.2 Where’s the help? 18 3.3 Using the help 20 3.4 “About” help files 23 3.5 Provider help 24 3.6 Interpreting command help 25 3.7 Common parameters 27 3.8 Summary 28 4 The basics of PowerShell syntax 29 4.1 Commands 30 Aliases: nicknames for commands 31 ■ Command name tab completion 32 4.2 Parameters 32 Truncating parameter names 34 ■ Parameter name tab completion 35 4.3 Typing trick: line continuation 35 4.4 Parenthetical commands and expressions 36 4.5 Script blocks 37 4.6 Summary 38 5 Working with PSSnapins and modules 39 5.1 There’s only one shell 39 5.2 PSSnapins vs. modules 40 5.3 Loading, autoloading, and profiles 41 5.4 Using extensions 41 Discovering extensions 41 ■ Loading extensions 43 Discovering extensions’ additions 43 ■ Managing extensions 44 5.5 Command name conflicts 44 5.6 Managing module autoloading 45 5.7 Summary 45
  • 13. CONTENTS ix 6 Operators 46 6.1 Logical and comparison operators 47 The –contains operator 48 ■ The -in and -notin operators 49 Boolean, or logical, operators 50 ■ Bitwise operators 51 6.2 Arithmetic operators 53 6.3 Other operators 55 String and array manipulation operators 55 Object type operators 56 ■ Format operator 57 Miscellaneous operators 58 6.4 Summary 59 7 Working with objects 60 7.1 Introduction to objects 61 7.2 Members: properties, methods, and events 63 7.3 Sorting objects 68 7.4 Selecting objects 69 Use 1: choosing properties 70 ■ Use 2: choosing a subset of objects 71 ■ Use 3: making custom properties 73 Use 4: extracting and expanding properties 75 Use 5: choosing properties and a subset of objects 79 7.5 Filtering objects 79 Simplified syntax 79 ■ Full syntax 81 7.6 Grouping objects 81 7.7 Measuring objects 83 7.8 Enumerating objects 84 Full syntax 85 ■ Simplified syntax 85 7.9 Importing, exporting, and converting objects 86 7.10 Comparing objects 90 7.11 Summary 92 8 The PowerShell pipeline 93 8.1 How the pipeline works 93 The old way of piping 94 ■ The PowerShell way of piping 95 8.2 Parameter binding ByValue 96 8.3 Pipeline binding ByPropertyName 98 8.4 Troubleshooting parameter binding 104
  • 14. CONTENTS x 8.5 When parameter binding lets you down 109 8.6 The pipeline with external commands 110 8.7 Summary 110 9 Formatting 111 9.1 The time to format 111 9.2 The formatting system 113 Is there a predefined view? 113 ■ What properties should be displayed? 113 ■ List or table? 114 9.3 The Format cmdlets 114 Formatting wide lists 114 ■ Formatting tables 115 Formatting lists 120 ■ Same objects, different formats 122 9.4 Eliminating confusion and “gotchas” 122 Formatting is the end of the line 122 ■ Select or format? 123 Format, out, export—which? 124 9.5 Summary 125 PART 2 POWERSHELL MANAGEMENT ..........................127 10 PowerShell Remoting 129 10.1 The many forms of remote control 130 10.2 Remoting overview 130 Authentication 131 ■ Firewalls and security 132 10.3 Using Remoting 132 Enabling Remoting 132 ■ 1-to-1 Remoting 133 1-to-many Remoting 134 ■ Remoting caveats 136 Remoting options 138 10.4 PSSessions 140 Creating a persistent session 140 ■ Using a session 140 Managing sessions 141 ■ Disconnecting and reconnecting sessions 141 10.5 Advanced session techniques 144 Session parameters 144 ■ Session options 145 10.6 Creating a custom endpoint 145 Custom endpoints for delegated administration 147
  • 15. CONTENTS xi 10.7 Connecting to nondefault endpoints 148 10.8 Enabling the “second hop” 149 10.9 Setting up WinRM listeners 150 10.10 Other configuration scenarios 152 Cross-domain Remoting 152 ■ Quotas 153 ■ Configuring on a remote machine 154 ■ Key WinRM configuration settings 154 Adding a machine to your Trusted Hosts list 155 ■ Using Group Policy to configure Remoting 156 10.11 Implicit Remoting 157 10.12 Summary 159 11 Background jobs and scheduling 160 11.1 Remoting-based jobs 160 Starting jobs 161 ■ Checking job status 162 ■ Working with child jobs 162 ■ Waiting for a job 164 ■ Stopping jobs 164 Getting job results 164 ■ Removing jobs 165 Investigating failed jobs 166 11.2 WMI jobs 166 11.3 Scheduled jobs 167 Scheduled jobs overview 168 ■ Creating a scheduled job 168 Managing scheduled jobs 169 ■ Working with scheduled job results 170 11.4 Job processes 170 Jobs created with Start-Job 171 ■ Jobs created with Invoke-Command 172 ■ Jobs created through the WMI cmdlets 173 ■ Jobs created through the scheduler 173 11.5 Summary 173 12 Working with credentials 174 12.1 About credentials 175 12.2 Using credentials 178 12.3 Crazy credentials ideas 179 Packaging your script 179 ■ Saving a credential object 179 Creating a credential without the GUI 181 Supporting credentials in your script 181 12.4 Summary 183
  • 16. CONTENTS xii 13 Regular expressions 184 13.1 Basic regular expression syntax 185 13.2 The –match operator 188 13.3 The select-string cmdlet 190 13.4 Switch statement 190 13.5 The REGEX object 192 13.6 Summary 195 14 Working with HTML and XML data 196 14.1 Working with HTML 196 Retrieving an HTML page 197 ■ Working with the HTML results 198 ■ Practical example 201 Creating HTML output 202 14.2 Working with XML 206 Using XML to persist data 206 ■ Reading arbitrary XML data 207 ■ Creating XML data and files 208 Using XML XPath queries 209 14.3 Summary 209 15 PSDrives and PSProviders 210 15.1 Why use PSProviders? 210 15.2 What are PSProviders? 211 15.3 What are PSDrives? 212 15.4 Working with PSDrives 213 Working with PSDrive items 214 ■ Working with item properties 216 15.5 Transactional operations 219 15.6 Every drive is different 221 15.7 Summary 223 16 Variables, arrays, hash tables, and scriptblocks 224 16.1 Variables 224 Variable names 225 ■ Variable types 226 ■ Being strict with variables 228 16.2 Built-in variables and the Variable: drive 230 16.3 Variable commands 231
  • 17. CONTENTS xiii 16.4 Arrays 232 16.5 Hash tables and ordered hash tables 235 Ordered hash tables 239 ■ Common uses for hash tables 241 Defining default parameter values 241 16.6 Scriptblocks 241 16.7 Summary 243 17 PowerShell security 244 17.1 PowerShell security goals 244 17.2 PowerShell security mechanisms 245 Script execution requires a path 245 Filename extension associations 246 17.3 Execution policy 247 A digital signature crash course 247 ■ Understanding script signing 249 ■ The execution policy in depth 251 17.4 The PowerShell security debate 255 17.5 Summary 256 18 Advanced PowerShell syntax 257 18.1 Splatting 257 18.2 Defining default parameter values 259 18.3 Running external utilities 263 18.4 Expressions in quotes: $($cool) 269 18.5 Parentheticals as objects 270 18.6 Increase the format enumeration limit 271 18.7 Hash tables as objects 272 18.8 Summary 274 PART 3 POWERSHELL SCRIPTING AND AUTOMATION ...275 19 PowerShell’s scripting language 277 19.1 Defining conditions 277 19.2 Loops: For, Do, While, Until 278 The For loop 278 ■ The other loops 280 19.3 ForEach 281 19.4 Break and Continue 283
  • 18. CONTENTS xiv 19.5 If . . . ElseIf . . . Else 284 19.6 Switch 286 19.7 Mastering the punctuation 289 19.8 Summary 290 20 Basic scripts and functions 291 20.1 Script or function? 291 20.2 Execution lifecycle and scope 292 20.3 Starting point: a command 293 20.4 Accepting input 293 20.5 Creating output 295 20.6 “Filtering” scripts 297 20.7 Moving to a function 299 20.8 Summary 300 21 Creating objects for output 301 21.1 Why output objects? 302 21.2 Syntax for creating custom objects 303 Technique 1: using a hash table 303 ■ Technique 2: using Select-Object 305 ■ Technique 3: using Add-Member 306 Technique 4: using a Type declaration 307 Technique 5: creating a new class 307 What’s the difference? 309 21.3 Complex objects: collections as properties 309 21.4 Applying a type name to custom objects 312 21.5 So, why bother? 313 21.6 Summary 316 22 Scope 317 22.1 Understanding scope 317 22.2 Observing scope in action 321 22.3 Dot sourcing 323 22.4 Manipulating cross-scope elements 324 22.5 Being private 328 22.6 Being strict 328 22.7 Summary 331
  • 19. CONTENTS xv 23 PowerShell workflows 332 23.1 Workflow overview 333 23.2 Workflow basics 334 Common parameters for workflows 335 ■ Activities and stateless execution 335 ■ Persisting state 337 Suspending and resuming workflows 337 Workflow limitations 337 ■ Parallelism 340 23.3 General workflow design strategy 341 23.4 Example workflow scenario 342 23.5 Writing the workflow 342 23.6 Workflows vs. functions 343 23.7 Specific workflow techniques 345 Sequences 345 ■ InlineScript 346 23.8 Running a workflow 349 Workflow jobs 349 ■ Suspending and restarting a workflow 350 ■ Workflow credentials 351 23.9 A practical example 351 23.10 Invoke-AsWorkflow 353 23.11 PSWorkflowSession 355 23.12 Troubleshooting a workflow 357 23.13 Summary 358 24 Advanced syntax for scripts and functions 359 24.1 Starting point 360 24.2 Advanced parameters 360 24.3 Variations on parameter inputs 365 24.4 Parameter aliases 366 24.5 Parameter validation 367 24.6 Parameter sets 372 24.7 WhatIf and Confirm parameters 373 24.8 Verbose output 375 24.9 Summary 378 25 Script modules and manifest modules 379 25.1 Making a script module 380 25.2 Exporting module members 382
  • 20. CONTENTS xvi 25.3 Making a module manifest 386 25.4 Creating dynamic modules 387 25.5 Summary 390 26 Custom formatting views 391 26.1 Object type names 392 26.2 Getting view templates 393 26.3 Starting a view file 393 26.4 Adding view types 394 26.5 Importing view data 397 26.6 Using named views 399 26.7 Going further 401 26.8 Summary 402 27 Custom type extensions 403 27.1 What are type extensions? 404 27.2 Creating and loading a type extension file 405 27.3 Making type extensions 407 AliasProperty 407 ■ ScriptProperty 407 ■ ScriptMethod 408 DefaultDisplayPropertySet 409 27.4 A complete example 409 27.5 Updating type data dynamically 411 27.6 Get-TypeData 414 27.7 Remove-TypeData 415 27.8 Summary 416 28 Data language and internationalization 417 28.1 Internationalization basics 418 28.2 Adding a data section 420 28.3 Storing translated strings 422 28.4 Testing localization 425 28.5 Summary 428 29 Writing help 429 29.1 Comment-based help 430 29.2 Writing About topics 432
  • 21. CONTENTS xvii 29.3 XML-based help 432 29.4 Summary 434 30 Error handling techniques 435 30.1 About errors and exceptions 436 30.2 Using $ErrorActionPreference and –ErrorAction 436 30.3 Using –ErrorVariable 438 30.4 Using $Error 439 30.5 Trap constructs 440 30.6 Try...Catch...Finally constructs 443 30.7 Summary 446 31 Debugging tools and techniques 447 31.1 Debugging: all about expectations 448 31.2 Write-Debug 456 31.3 Breakpoints 460 31.4 Using Set-PSDebug 463 31.5 Debugging in third-party editors 465 31.6 Summary 465 32 Functions that work like cmdlets 466 32.1 Defining the task 467 32.2 Building the command 468 32.3 Parameterizing the pipeline 469 32.4 Adding professional features 472 32.5 Error handling 472 Adding verbose and debug output 474 ■ Defining a custom object name 477 32.6 Making it a function and adding help 477 32.7 Creating a custom view 479 32.8 Creating a type extension 480 32.9 Making a module manifest 481 32.10 Summary 484
  • 22. CONTENTS xviii 33 Tips and tricks for creating reports 485 33.1 What not to do 485 33.2 Working with HTML fragments and files 487 Getting the information 488 ■ Producing an HTML fragment 488 ■ Assembling the final HTML page 489 33.3 Sending email 492 33.4 Summary 493 PART 4 ADVANCED POWERSHELL ...............................495 34 Working with the Component Object Model (COM) 497 34.1 Introduction to COM objects 498 34.2 Instantiating COM objects in PowerShell 500 34.3 Accessing and using COM objects’ members 500 34.4 PowerShell and COM examples 503 34.5 Summary 504 35 Working with .NET Framework objects 505 35.1 Classes, instances, and members 506 35.2 .NET Framework syntax in PowerShell 507 35.3 .NET support in PowerShell 508 35.4 Accessing static members 509 35.5 Finding the right framework bits 509 35.6 Creating and working with instances 514 35.7 Summary 516 36 Accessing databases 517 36.1 Native SQL vs. OLEDB 518 36.2 Connecting to data sources 518 36.3 Querying data 519 Databases with DataAdapters 520 ■ Databases with DataReaders 520 36.4 Adding, changing, and deleting data 521 36.5 Calling stored procedures 521 36.6 A module to make it easier 522 36.7 Summary 524
  • 23. CONTENTS xix 37 Proxy functions 525 37.1 The purpose of proxy functions 525 37.2 How proxy functions work 526 37.3 Creating a basic proxy function 526 37.4 Adding a parameter 528 37.5 Removing a parameter 532 37.6 Turning it into a function 534 37.7 Summary 536 38 Building a GUI 538 38.1 WinForms via PowerShell Studio 539 Creating the GUI 540 ■ Adding the code 543 Using the script 548 38.2 Windows Presentation Foundation (WPF) and ShowUI 552 38.3 WinForms vs. WPF 554 38.4 Ideas for leveraging a GUI tool 555 38.5 Summary 556 39 WMI and CIM 557 39.1 What is WMI? 558 39.2 WMI cmdlets 559 Get-WmiObject 559 ■ Remove-WmiObject 561 Set-WmiInstance 562 ■ Invoke-WmiMethod 563 Register-WmiEvent 566 39.3 CIM cmdlets 567 Get-CIMClass 570 ■ Get-CimInstance 571 Remove-CimInstance 573 ■ Set-CimInstance 574 Invoke-CimMethod 574 ■ Register-CimIndicationEvent 575 39.4 CIM sessions 576 39.5 “Cmdlets over objects” 578 39.6 Summary 583 40 Best practices 584 40.1 PowerShell general best practices 584 40.2 PowerShell scripting best practices 585 40.3 PowerShell in the enterprise best practices 587 index 589
  • 25. xxi preface Windows PowerShell is viewed by many IT professionals as a necessary evil; we see it as a management marvel. The challenge from the beginning has been to wrap one’s head around the PowerShell paradigm of an object-based shell. Some people view PowerShell as just another scripting language like VBScript. The truth is that Power- Shell is an automation and management engine. You can run this engine in a tradi- tional console application, which is how most IT pros are first exposed to it. You can run it in a graphical environment like the PowerShell Integrated Scripting Environ- ment (ISE), or through a third-party tool like PowerGUI or PowerShell Plus. As you might imagine, the third version of a product offers substantially more fea- tures and benefits than the first, and PowerShell 3.0 fits this model. This version of PowerShell naturally builds on what came before, but it takes off from there. If you think of Windows 8 and Windows Server 2012 as operating systems for the cloud, then PowerShell 3.0 is the automation and management engine for the cloud, although PowerShell “scales down” to help you better manage any size environment. Collectively, we have close to 70 years of IT experience. We have worked with PowerShell from its days as a beta product and have written on the topic for nearly as long. Our goal is to bring this knowledge and experience into a single reference book. Notice the key word, “reference.” This is not a how-to or teach yourself PowerShell book, although you can learn much from reading it cover to cover. Rather, this book is intended as the reference guide you keep at your desk or on your mobile device so that when you need to better understand a topic, like PowerShell remoting, you have a place to which you can turn.
  • 26. PREFACE xxii We have tried to keep our examples practical and targeted towards IT professionals responsible for Windows system administration. It is our hope that this will be the book you go to for answers.
  • 27. xxiii acknowledgments As you can imagine, a book of this scope and magnitude is not an easy undertaking, even with three coauthors. There are many, many people who had a hand in mak- ing this possible. First, we’d like to thank the entire PowerShell product team at Microsoft. Many of them took time from their busy schedules to answer our ques- tions and offer guidance on a number of new features, even while they were still being developed! The authors would also like to thank the fine folks at Manning Publications: Cynthia Kane, Karen Miller, Maureen Spencer, Liz Welch, Linda Recktenwald, Janet Vail, and Mary Piergies. They have taken what can be a grueling process and turned it into something pleasant yet productive in helping us bring this book to publication. That is not easy. We also thank the cadre of what we think of as “real-world” reviewers who offered their opinions on how we could make this a book that they, and you, would want on your bookshelf. They include Adam Bell, Andre Sune, Bart Vermeulen, Bruno Gomes, Eric Flamm, Eric Stoker, Gary Walker, Greg Heywood, Innes Fisher, James Berkenbile, Jelmer Siljee, Jonathan Medd, Kais Ayari, Klaus Schulte, Mike Shepard, Peter Monadjemi, Richard Beckett, Rolf Åberg, Santiago I. Cánepa, Thomas Lee, and Trent Whiteley. We would especially like to thank Aleksandar Nikolic for his time and dedication in reviewing the technical content of our book. Aleksandar shares our desire to pro- duce the best possible PowerShell reference and we truly appreciate his efforts.
  • 28. ACKNOWLEDGMENTS xxiv DON would like to thank everyone at Manning for their support of, and commitment to, this project. He’d also like to thank his coauthors for their hard work, and his fam- ily for being so giving of their time. RICHARD would like to thank everyone who has taken the time to comment on the book and the PowerShell community for their willingness to share. He would like to thank Don and Jeff for making this a very enjoyable experience—working across eight timezones makes for some interesting conversations. JEFF would like to extend a special thanks to Steve Murawski and Travis Jones for their PowerShell 3.0 insights. He would also like to thank his coauthors for making this one of the best authoring experiences possible.
  • 29. xxv about this book This book was written as a reference for system administrators. You can read the book cover to cover, and we’ve tried to arrange the chapters in a logical progression, but, in the end, it works best as a reference, where you can explore a topic more deeply in the chapter that is devoted to a particular subject. Chapter 1 will tell you more about what you will learn in the book, and what you need to know before you start. The 40 chapters in the book are arranged into four parts, as follows: ■ Part 1 “Fundamentals” includes chapters 1 through 9 which cover the basics associated with using PowerShell. Although we didn’t write this book as a tuto- rial, there are a few basics you’ll need to explore before you can use PowerShell effectively: the pipeline, the concept of PowerShell hosts, the shell’s help sys- tem, and so forth. We’ll dive deeper into some of these topics than a tutorial normally would, so even if you’re already familiar with these foundational con- cepts, it’s worth a quick read-through of these chapters. ■ Part 2 “PowerShell management” covers topics such as remote control, back- ground jobs, regular expressions, and HTML and XML. These are just a few of the core technologies accessible within PowerShell that make server and client management easier, more scalable, and more effective. Chapters 10 through 18 tackle these technologies individually, and we dive as deeply as we can into them, so that you can master their intricacies and subtleties. ■ Part 3 “PowerShell Scripting and Automation” includes chapters 19 through 33 which have a single goal: repeatability. Using PowerShell’s scripting language,
  • 30. ABOUT THIS BOOK xxvi along with associated technologies like workflow, you can begin to create reus- able tools that automate key tasks and processes in your environment. ■ Part 4 “Advanced PowerShell” consists of chapters 34 through 40. One of Power- Shell’s greatest strengths is its ability to connect to other technologies, such as WMI, CIM, COM, .NET, and a host of other acronyms. The chapters in part 4 look at each of these and demonstrate how PowerShell can utilize them. We give you a starting place for doing this, and then we provide you with some direction for further independent exploration. Code conventions and downloads All source code in listings or in text is in a fixed-width font like this to separate it from ordinary text. Code annotations accompany many of the listings, highlighting important concepts. In some cases, numbered bullets link to explanations that follow the listing. The code samples are based on PowerShell 3.0. We intended the samples to be instructive, but we did not design them for production use. They may not always be the “best” PowerShell—our code examples were designed to reinforce concepts and make points. We have tried to fit code samples into the confines of a printed page, which means that sometimes we have had to bend some rules. You are welcome to try the code snip- pets on your computer, but remember that the book is not intended as a tutorial. Lon- ger code samples are displayed as code listings; we don’t expect you to type these. If you want to try them, the files can be downloaded from the book’s page on the pub- lisher’s website at www.manning.com/PowerShellinDepth. We, along with our technical reviewer, have strived to test and retest everything. But sometimes errors will still sneak through. We encourage you to use the Author Online forum for this book at www.manning.com/PowerShellinDepth to post any cor- rections, as well as your comments or questions on the book’s content. Author Online Purchase of PowerShell in Depth includes free access to a private web forum run by Manning Publications, where you can make comments about the book, ask technical questions, and receive help from the authors and from other users. To access the forum and subscribe to it, point your web browser to www.manning.com/PowerShellinDepth. This page provides information on how to get on the forum once you are registered, what kind of help is available, and the rules of conduct on the forum. Manning’s commitment to our readers is to provide a venue where a meaningful dia- logue between individual readers and between readers and the authors can take place. It is not a commitment to any specific amount of participation on the part of the authors, whose contribution to the book’s forum remains voluntary (and unpaid). We suggest you try asking the authors some challenging questions, lest their interest stray! The Author Online forum and the archives of previous discussions will be accessi- ble from the publisher’s website as long as the book is in print.
  • 31. xxvii about the authors DON JONES has more than 20 years of experience in the IT industry, and is a recog- nized expert in Microsoft’s server platform. He’s a multiple-year recipient of Micro- soft’s prestigious Most Valuable Professional (MVP) award, and writes the “Windows PowerShell” column for Microsoft TechNet Magazine. Don has authored more than 50 books on information technology topics, including three books in the popular Learn PowerShell in a Month of Lunches series from Manning. He is a regular and top- rated speaker at numerous technology conferences and symposia worldwide, and a founding director of PowerShell.org, a community-owned and community-operated resource for PowerShell users. RICHARD SIDDAWAY has been working with Microsoft technologies for over 20 years having spent time in most IT roles. He has always been interested in automation tech- niques (including automating job creation and submission on mainframes many years ago). PowerShell caught his interest and Richard has been using it since the early beta versions. He regularly blogs about PowerShell, and using PowerShell, at http:/ / msmvps.com/blogs/richardsiddaway/default.aspx. Richard founded and still runs the UK PowerShell User Group and has been a PowerShell MVP for the last five years. A regular speaker and writer on PowerShell topics, his previous Manning books include PowerShell in Practice and PowerShell and WMI. JEFFERY HICKS is a Microsoft MVP in Windows PowerShell, Microsoft Certified Trainer and an IT veteran with 20 years of experience, much of it spent as an IT consultant
  • 32. ABOUT THE AUTHORS xxviii specializing in Microsoft server technologies. He works today as an independent author, trainer, and consultant, and he has coauthored two earlier books for Manning. Jeff writes the popular Prof. PowerShell column for MPCMag.com and is a regular contributor to the Petri IT Knowledgebase. You can keep up with Jeff at his blog http:/ /jdhitsolutions.com/blog or on Twitter @jeffhicks The authors would love to hear from you and are eager to help spread the good news about PowerShell. We hope you’ll come up to us at conferences like TechEd and let us know how much (hopefully) you enjoyed the book. If you have any other PowerShell questions, we encourage you to use the forums at PowerShell.org, where we all are active participants.
  • 33. xxix about the cover illustration The figure on the cover of PowerShell in Depth is captioned a “Man from Split, Dalmatia.” The illustration is taken from the reproduction published in 2006 of a 19th-century collection of costumes and ethnographic descriptions entitled Dalmatia by Professor Frane Carrara (1812–1854), an archaelogist and historian and the first director of the Musuem of Antiquity in Split, Croatia. The illustrations were obtained from a helpful librarian at the Ethnographic Museum (formerly the Museum of Antiquity), itself situ- ated in the Roman core of the medieval center of Split: the ruins of Emperor Diocle- tian’s retirement palace from around AD 304. The book includes finely colored illustrations of figures from different regions of Croatia, accompanied by descriptions of the costumes and of everyday life. The man on the cover is wearing dark blue woolen trousers and a black vest over a white linen shirt. Over his shoulder is a brown jacket, and a red belt and a red cap complete the outfit; in his hand he holds a long pipe. The elaborate and colorful embroidery on his costume is typical for this region of Croatia. Dress codes have changed since the 19th century and the diversity by region, so rich at the time, has faded away. It is now hard to tell apart the inhabitants of different continents, let alone different towns or regions. Perhaps we have traded cultural diver- sity for a more varied personal life—certainly for a more varied and fast-paced techno- logical life. We at Manning celebrate the inventiveness, the initiative, and, yes, the fun of the computer business with book covers based on the rich diversity of regional life of two centuries ago‚ brought back to life by the pictures from this collection.
  • 35. Part 1 PowerShell fundamentals In part 1, we’ll cover some of the basics associated with using PowerShell. Although we didn’t write this book as a tutorial, there are nonetheless a few basics you’ll need to explore before you can use PowerShell effectively: the pipe- line, the concept of PowerShell hosts, the shell’s help system, and so forth. We’ll dive a bit deeper into some of these topics than a tutorial normally might do, so even if you’re already familiar with these foundational concepts, it’s worth a quick read-through of these chapters.
  • 37. 3 Introduction As of this writing, Windows PowerShell is approaching its sixth year of existence and in its third major release. In that time, it’s changed the way people look at administering many Microsoft, and even some non-Microsoft, products. Although the graphical user interface (GUI) will always be an important part of administra- tion in many ways, PowerShell has given administrators options: Use an easy, intui- tive GUI; manage from a rich, interactive command-line console; or fully automate a simple scripting language. We’re delighted that so many administrators have started using PowerShell, and we’re honored that you’ve chosen this book to fur- ther your own PowerShell education. 1.1 Who this book is for We wrote this book for system administrators, not developers. In the Microsoft world, administrators go by the catchall title “IT professional” or “IT pro” and that’s who we had in mind. As such, we assume you’re not a full-time programmer, This chapter covers ■ What the book will and won’t teach ■ The boundaries of this book ■ Going beyond PowerShell
  • 38. 4 CHAPTER 1 Introduction although if you have some programming or scripting experience it’ll make certain parts of PowerShell easier to learn. We assume you’re primarily interested in automating various administrative tasks and processes, or at least being more efficient, but we don’t make any assumptions about the products with which you work. You may be an Exchange Server administra- tor, or maybe SharePoint or SQL Server is your thing. Perhaps you manage Active Directory, or you’re in charge of file servers. You may even manage a Citrix or VMware environment (yes, they can be managed by PowerShell). It doesn’t matter, because what we’ll focus on in this book is the core technologies of PowerShell itself: the techniques and features you’ll need to use no matter what products you’re administering. We do use Active Directory in a few examples, but every technique, pattern, practice, and trick we show you will apply equally well, no matter where you’ve chosen to use PowerShell. 1.2 What this book will teach you You can certainly read this book cover to cover, and we’ve tried to arrange the chap- ters in a logical progression. But in the end, we intend for this book to be a reference. Need to figure out PowerShell Remoting? Skip to that chapter. Confused about how commands pipe data from one to another? We’ve written a chapter for that. Need to access a database from within a PowerShell script? There’s a chapter for that. We’ve no intention of making you a programmer—we don’t claim to be program- mers—we all have backgrounds as IT pros. Yes, PowerShell can support some robust scripts, but you can also accomplish a lot by running commands. If you have program- ming experience, it’ll serve you well, and you may be tempted to approach PowerShell more as a scripting language, which is fine. If you’ve never scripted or programmed a single line of code, you’ll probably see PowerShell as a pure command-line interface, where you run commands to make stuff happen, and that’s fine, too. Either way you win because you get to automate your tedious, repetitive work. 1.3 What this book won’t teach you We assume you’re already an experienced administrator and that you’re familiar with the inner workings of whatever technology you manage. We aren’t going to teach you what an Active Directory user account is, or what an Exchange mailbox does, or how to create a SharePoint site. PowerShell is a tool that lets you accomplish administrative tasks, but like any tool it assumes you know what you’re doing. To use a noncomputer analogy, PowerShell is a hammer, and this book will teach you how to swing that hammer and not smash your thumb. We won’t teach you about building houses, though—we assume you already know how to do that, and you’re looking for a more efficient way to do it than pounding nails with a rock.
  • 39. 5 Beyond PowerShell 1.4 Where we drew the line It’s safe to say that PowerShell can’t do everything for you. You’ll find some things with which it’s completely incapable of helping, as with any technology. But you’ll also find tasks for which PowerShell works well. And you’ll encounter that weird middle ground where you could do something in PowerShell, but to do it you’d have to go beyond the strict boundaries of what PowerShell is. For example, PowerShell doesn’t natively contain a way to map a network printer. You could instantiate a Component Object Model (COM) object to accomplish the task from within PowerShell, but it has nothing to do with PowerShell. Instead, it’s the shell giving you a way to access completely external technologies. In these cases (which are becoming increasingly rare in the latest version of Windows), we’ll only say, “You can’t do that in PowerShell yet.” We know our statement isn’t 100 percent true, but we want to keep this book focused on what PowerShell is and what it does natively. If we turn this book into “everything you can do with PowerShell natively, plus all the external stuff like .NET and COM and so on that you can get to from Power- Shell,” it’d grow to 7,000 pages in length and we’d never finish. That said, we’re including material in the book on using some of these external technologies, along with some guidance on where you can find resources to educate yourself on them more completely if you’ve a mind to do so. 1.5 Beyond PowerShell PowerShell is a lot like the Microsoft Management Console (MMC), with which you’re probably familiar. On its own, it’s useless. Both the MMC and PowerShell only become useful when you add extensions, which in the MMC would be “snap-ins,” and in Power- Shell would be either a “snap-in” or a “module.” Those extensions give you access to Exchange, Active Directory, SharePoint, SQL Server, and so on. Understand that the folks at Microsoft who write PowerShell don’t write the exten- sions. They provide some tools and rules for the developers who do create extensions, but their job is to create the core PowerShell stuff. Extensions are made by other product teams: The Exchange team makes the Exchange PowerShell extension, the Active Directory team makes its extension, and so on. If you’re looking at a particular extension and don’t like what you see, blame the product team that produced it, not PowerShell. If you’d like to administer something—maybe WINS Server, for exam- ple—and PowerShell has no way to administer it, it’s not the PowerShell team’s fault. Blame the owners of the technology you’re trying to work with, and encourage them to get on board and produce a PowerShell extension for their product. This division of labor is one reason why we’re keeping this book focused on the core of PowerShell. That core is what you’ll use no matter what extensions you end up deploying to achieve your administrative goals.
  • 40. 6 CHAPTER 1 Introduction 1.6 Ready? Okay, that’s enough of an introduction. If you want to follow along, make sure you have PowerShell v3 installed on a Windows 7 Desktop, or run a Windows 8 client. Now, pick a chapter and jump in.
  • 41. 7 PowerShell hosts PowerShell can be confusing to use because it behaves differently in different situ- ations. Here’s an example from PowerShell v2: When you run the Read-Host com- mand in the PowerShell.exe console, it behaves differently than if you run that same command in the PowerShell Integrated Scripting Editor (ISE). The reason you encounter these differences has to do with the fact that you don’t interact directly with PowerShell. Instead, you give commands to the PowerShell engine by means of a host. It’s up to the host to determine how to interact with the Power- Shell engine. NOTE The difference in the response of Read-Host between the console and the ISE has been eliminated in PowerShell v3. This chapter covers ■ The purpose of PowerShell hosts ■ The PowerShell console and ISE hosts ■ The differences between 64-bit and 32-bit hosts ■ PowerShell transcripts
  • 42. 8 CHAPTER 2 PowerShell hosts The PowerShell engine is a set of .NET Framework classes stored in a DLL file. You can’t interact with it directly. Instead, the application you interact with loads the engine. For example, if you’ve ever used the Exchange Server 2007 (or later) graphi- cal management console (called the Exchange Management Console, or EMC), then you’ve used a PowerShell host. The EMC lets you interact by clicking icons, filling in dialog boxes, and so forth, but it’s PowerShell that performs the actions it takes. You never “see” the shell, but it’s hiding under the GUI. That’s why it can show you the PowerShell commands for the actions it has performed. Exchange also provides a console-based shell that exposes the underlying PowerShell engine. When we talk about “using PowerShell,” we’re most often talking about using it through a host that looks more like a command-line shell. Microsoft provides two dif- ferent hosts for that purpose: the console and the ISE. Third-party vendors can also pro- duce host applications, and many popular PowerShell editors—PrimalScript, PowerGUI, PowerShell Plus, PowerSE, and so forth—all host the PowerShell engine. How you interact with the shell and what your results look like will depend on the host you’re using. Results might look and work one way in the Microsoft-supplied console, but they might look and work differently in a third-party application—or in some cases may not work at all. Conversely, some things that have worked in a third-party host don’t work in the Microsoft hosts. TIP Remember that if things work in one host but not in another, it’s mostly likely due to the differences in the hosts rather than it being a PowerShell error. For this book, we’ll assume you’re using one of the two Microsoft-supplied hosts, which we’ll describe in this chapter. 2.1 32-bit vs. 64-bit, and administrator vs. not The way you access the shortcuts for Microsoft’s PowerShell host applications depends on the version of the operating system and the install options you’ve chosen. The first thing you need to be aware of is that PowerShell v3 isn’t available on all versions of Windows. It’s installed as part of the base build on ■ Windows 8 x86 and x64 ■ Windows Server 2012 x64 The Windows Management Foundation (WMF) download (PowerShell v3, WinRM v3, and the new WMI API) is available for ■ Windows 7 SP1 (or above) x86 and x64 ■ Windows Server 2008 R2 SP1 (or above) x64 ■ Windows Server 2008 SP2 (or above) x86 and x64 The WMF download is available from www.microsoft.com/en-us/download/details.aspx? id=34595. Check the version you need for your system in the download instructions. NOTE If you’re using Windows XP, Windows Vista, or any flavor of Windows Server 2003, you can’t install PowerShell v3.
  • 43. 9 32-bit vs. 64-bit, and administrator vs. not In Windows 8 and Windows Server 2012, the way you access applications has changed. You use the Start screen instead of the Start menu. If you’re on the Windows Desktop, press the Win button to access the Start screen. Scroll to the right to find the Power- Shell icon. Alternatively, press Win-Q to access the application search menu. On earlier versions of Windows you’ll find shortcuts to Microsoft’s host applica- tions on your computer’s Start menu. If you’re on a Server Core (Windows Server 2008 R2 or later) system that doesn’t have a Start menu, run powershell to start the console host. You’ll need to install PowerShell because it isn’t part of the default Win- dows Server 2008 R2 server core install. The shortcuts can usually be found under Accessories > Windows PowerShell. NOTE PowerShell and the old command prompt use the same underlying console technology, which means you can type PowerShell in a command prompt or cmd in a PowerShell console and “switch” to the other shell. Typing Exit will revert back to the starting shell. On a 32-bit system (on any Windows version), you’ll find shortcuts for PowerShell—what we refer to as “the console”—and for the PowerShell ISE. Obviously, these shortcuts both point to 32-bit versions of PowerShell. But on a 64-bit system you’ll find four shortcuts: ■ Windows PowerShell—the 64-bit console ■ Windows PowerShell ISE—also 64-bit ■ Windows PowerShell (x86)—the 32-bit console ■ Windows PowerShell ISE (x86)—also 32-bit It’s important to run the proper version, either 32-bit or 64-bit. PowerShell itself behaves the same either way, but when you’re ready to load extensions you can only load ones built on the same architecture. The 64-bit shell can only load 64-bit exten- sions. If you have a 32-bit extension, you’ll have to load it from the 32-bit shell. Once you launch, the window title bar will also display “(x86)” for the 32-bit versions, which means you can always see which one you’re using. TIP We recommend that you pin PowerShell to your taskbar. It makes access much quicker. Right-clicking the icon on the taskbar provides access to PowerShell and ISE in addition to providing links to run as Administrator for both hosts. On computers that have User Account Control (UAC) enabled, you’ll need to be a bit careful. If your PowerShell window title bar doesn’t say “Administrator,” you’re not running PowerShell with Administrator authority. WARNING Watch the top-left corner of the host as it starts. It will say “Admin- istrator: Windows PowerShell” or “Administrator: Windows PowerShell ISE” during at least some of the startup period. Some of us, like Richard, modify the title bar to display the path to the current working directory so the title bar won’t show “Administrator” once the profile has finished executing.
  • 44. 10 CHAPTER 2 PowerShell hosts If you’re not running as an Administrator, some tasks may fail with an “Access Denied” error. For example, you can only access some WMI classes when you’re using Power- Shell with the elevated privileges supplied by running as Administrator. If your title bar doesn’t say “Administrator,” and you need to be an Administrator to do what you’re doing, close the shell. Reopen it by right-clicking one of the Start menu short- cuts and selecting Run as Administrator from the context menu. That’ll get you a win- dow title bar like the one shown in figure 2.1, which is what you want. In Windows 8, either right-click the taskbar shortcut or right-click the title on the Start screen to access the option Run as Administrator. It’s always worth taking a moment to verify whether your session is elevated before continuing with your work. The PowerShell console is the simpler of the two available hosts, which is why we’ll consider it before ISE. 2.2 The console Most people’s first impression of PowerShell is the Microsoft-supplied console, shown in figure 2.2. This console is built around an older piece of console software that’s built into Windows—the same one used for the old Cmd.exe shell. Although Power- Shell’s programmers tweaked the console’s initial appearance—it has a blue back- ground rather than black, for example—it’s still the same piece of software that’s been more or less unchanged since the early 1990s. As a result, it has a few limita- tions. For example, it can’t properly display double-byte character set (DBCS) lan- guages, making it difficult to use with Asian languages that require a larger character set. The console also has primitive copy-and-paste functionality, along with fairly sim- plistic editing capabilities. You may wonder then, why use the console? If you’ve ever used a command-line shell before, even one in a Unix or Linux environment, the console looks and feels familiar. That’s the main reason. If you’re using Server Core, then the console is your only choice, because the ISE won’t run on Server Core. Figure 2.1 An elevated PowerShell session from Windows 8. Notice the Administrator label in the caption.
  • 45. 11 The console NOTE “Server Core” is a term that originated in Windows Server 2008. In Windows Server 2012, “Server Core” is the default server installation that doesn’t have the “Server Graphical Shell” feature installed. PowerShell wasn’t available on the Windows Server 2008 version of Server Core, but it’s available in Windows Server 2008 R2 and later. Within the console, you can use a few tricks to make it a bit easier to work with: ■ Pressing the up and down arrows on your keyboard will cycle through the com- mand history buffer, enabling you to recall previous commands, edit them, and run them again. ■ Pressing F7 will display the command history buffer in a pop-up window. Use the up and down arrow keys to select a previous command, and then either press Enter to rerun the command or press the right arrow key to display the command for editing. ■ Use your mouse to highlight blocks of text by left-clicking and dragging. Then, press Enter to copy that block of text to the Windows clipboard. Quick Edit Mode must be enabled in the console’s properties for this to work. ■ Right-click to paste the Windows clipboard contents into the console. ■ Use the Tab key to complete the PowerShell cmdlet, function, and parameter names. In PowerShell v3, variable names can also be completed in this way. You can also do a few things to make the console more comfortable for yourself. Click the control box, which is at the top-left corner of the console window, and select Prop- erties. You’ll want to make a few adjustments in this dialog box: ■ On the Options tab, you can increase the command history buffer. A bigger buffer takes more memory but preserves more of the commands you’ve run, allowing you to recall them and run them again more easily. Figure 2.2 The Windows PowerShell console from Windows 8
  • 46. 12 CHAPTER 2 PowerShell hosts ■ On the Colors tab, choose text and background colors you’re comfortable reading. ■ On the Font tab, select a font face and size you like. This is important: You want to be sure you can easily distinguish between the single quote and backtick characters, between parentheses and curly brackets, and between single and double quotes. Distinguishing these characters isn’t always easy to do using the default font. The backtick and single quote confusion is particularly annoying. NOTE On a U.S. keyboard, the backtick character is located on the upper-left key, under the Esc key. It shares space with the tilde (~) character. It’s also referred to as a “grave accent mark.” On non-U.S. keyboards, you may find it in a different location. ■ On the Layout tab, make sure both Width settings are the same. The bottom one controls the physical window size, whereas the top one controls the logical width of the window. When they’re both the same, you won’t have a horizontal scrollbar. If the upper “screen buffer” width is larger than the “window size,” you’ll have a hori- zontal scrollbar. That means viewing much of PowerShell’s output will require hor- izontal scrolling, which can become cumbersome and annoying to work with. As you’re customizing your console window, take a moment to make sure it can dis- play all the characters from the character set with which you work. If any characters aren’t displaying properly, you may want to switch to the PowerShell ISE instead. Its ability to use TrueType fonts and to display DBCS languages makes it a real advantage. 2.3 The PowerShell ISE The PowerShell Integrated Scripting Environment, or ISE (usually pronounced “aye ess eee,” not “ice”), was created to offer a better script-editing experience than Win- dows Notepad, as well as provide a console experience that supports the use of DBCS languages and TrueType fonts. In general, the ISE works similarly to the console host, with a few exceptions: ■ The ISE can maintain several PowerShell runspaces in a single window by placing each onto a separate tab. Each runspace is an instance of PowerShell, much like opening multiple console windows. ■ The ISE can have multiple PowerShell scripts open simultaneously. Each is avail- able through a separate tab. ■ The ISE displays graphical dialog boxes for many prompts and messages, rather than displaying them on a command line as text. ■ The ISE doesn’t support transcripts, which we’ll describe later in this chapter. ■ You can change the font, starting size, and color schemes by selecting Tools from the menu and then selecting the appropriate options. To adjust the text display size, use the slider at the bottom right of the ISE window. NOTE Server operating systems don’t have the ISE installed by default. If you need it, you can install it using Server Manager like any other Windows feature.
  • 47. 13 The PowerShell ISE You can also use PowerShell to install ISE on servers. The command syntax is Add-WindowsFeature -Name PowerShell-ISE. The ISE supports two basic layouts, which are controlled by the three buttons on its toolbar. The default layout, shown in figure 2.3, uses two vertically stacked panes. The top pane is the script editor, and the bottom pane is where you can interac- tively type commands and receive output. In PowerShell v3, combining the interactive and output panes effectively duplicates the PowerShell console. Clicking the second layout button in the toolbar gives you the layout shown in fig- ure 2.4, where the script editor takes up one side and the console takes up the other side. Finally, the last button switches to a full-screen editor, which is useful if you’re working on a long script. In some views, you’ll notice that the script pane has a little blue arrow in the top-right corner. This can be used to hide or expose the script pane. The other toolbar buttons, labeled in figure 2.5, provide access to the majority of the ISE’s functions. You’ll also find additional options on the menu. The File, Edit, and View menus are self-explanatory, and we’ll discuss the Debug menu when we come to the topic of debugging in chapter 31. Let’s try something: In the ISE, select New PowerShell Tab from the File menu. (You’ll also see a Remote PowerShell Tab option. We’ll discuss that in chapter 10 on Remoting.) What pops up is a whole new instance of PowerShell, called a runspace, which we mentioned earlier. Each tab has its own set of script file tabs, with each file tab representing a single script file. Each PowerShell tab also has its own output area Figure 2.3 The default ISE layout uses two vertically stacked panes.
  • 48. 14 CHAPTER 2 PowerShell hosts Figure 2.4 The split view gives you more room to edit a script. Figure 2.5 Getting to know the ISE toolbar can save you time when performing common tasks.
  • 49. Discovering Diverse Content Through Random Scribd Documents
  • 50. Even Watch the Dog was happy. He was lying at the foot of the tree, with his nose on his paws as though he expected to stay there all day, and wagging his tail. But Louie Thomson, perched on one of its branches in the cold wind, was very unhappy. Whenever he moved Watch would raise the hair all along his back and growl, and the Red Cow would roll her scary eyes at him. “Hey, Tommy!” he called. “Drive off those brutes and let me come down!” “No, I won’t,” said Tommy. “This is two times you’ve cheated me. You cheated me with that old trap, and now you tried to come over here into my very own woods and catch my very own Beasts. That’s stealing. I’m going to let them watch you while I go up to the house and get my father to come for you.” Of course not one of the Woodsfolk knew what he meant. But they knew he was very angry. “Oh, please, please don’t do that!” begged Louie. “I’ll promise never to set foot in your woods again. Honest, cross my heart and hope to die, I will! Please let me go this time.” Nibble sat straight up and listened hard. For Louie sounded just like Chatter Squirrel the night of the Terrible Storm when he was so terribly afraid. “My whiskers, but isn’t Tommy wonderful,” he breathed to Watch. “You and the Red Cow can scare that Man when you can reach him, but Tommy scares him without doing anything.” And he came close up to Tommy’s tall rubber boots and cocked his head on one side, trying to see how Tommy did it. “I know you’ll promise,” Tommy was saying, “and you’ll keep it, too, or else I’ll know about it.” He just meant he and Watch would find Louie’s footprints. But Louie saw that rabbit sitting by Tommy and looking exactly as though he were talking to him. “And if you want your traps,” Tommy went on, “you’ll have to get that muskrat to find them.” He just meant he’d thrown them into the pond. But Louie Thomson didn’t know what to think of that. He guessed perhaps he’d better leave Tommy Peele and his wild things very
  • 52. CHAPTER V NIBBLE TELLS ONE SECRET AND HEARS ANOTHER Now when Tommy Peele followed Watch back to the woods it was because he thought the old dog was chasing Nibble Rabbit. Then he made up his mind Nibble had warned Watch about that bad Louie Thomson. He never dreamed Nibble had whispered a secret that belonged to the Red Cow. So as soon as he’d made Louie promise to behave, he whistled to Watch and began to lead the Red Cow away so Louie could climb down. Well, right then the Red Cow remembered that secret she had to show him. So she insisted on leading him. She fairly galloped around the end of the thicket, with Tommy running after her in his tall rubber boots and Watch bounding after him. But Nibble took a short cut through his tunnel. And he met Doctor Muskrat coming to meet him. “Climp, clump, climp, clump!” went a sound outside. “What’s that?” asked Doctor Muskrat. Nibble peered along the ground. And he could see Louie Thomson’s boots moving very fast. “It’s that Man,” he exclaimed. “He’s running like Silvertip the Fox did when the Red Cow took after him.” “Fine!” chuckled Doctor Muskrat. “He’ll never bring his wicked jaws back here again. And we can thank Tommy Peele for that.” Then there was another sound. “What’s that?” asked Nibble. And Doctor Muskrat laughed. For it was Tommy Peele squealing with surprise because he’d found the secret that belonged to the Red Cow. “A calf! Oh, the cute little thing!”
  • 53. The Red Cow walked around and around the trunk of that big tree roaring at him. So Nibble and Doctor Muskrat both crept back down the tunnel to watch what was going on. The calf raised his head and looked at Tommy; then he got up on his shaky legs and sniffed at him. Because Tommy was a strange Beast with a strange smell and even a baby knows enough to be careful about strange things. But when he touched his little turned-up nose to the hand Tommy held out to him he smelled his mother. You know Tommy had been stroking her. So the foolish little rascal put out his little pink tongue, trying to lick
  • 54. Tommy’s fingers. And wasn’t his mother pleased because they were friends the very first thing! Watch led the way, and Tommy walked beside the Red Cow and helped to steer her wobbly-legged calf all the way up to the barn. And the baby kept trying to kick up his silly little heels the way Nibble used to when he felt playful. And he just would run splash into all the puddles, and bunt and wriggle when they caught him. The Red Cow kept getting prouder and prouder every step, but even she was glad when they got safely home with him. Nibble went with them as far as the Pasture. Doctor Muskrat was enjoying a nice sweet flag-root (the first one he’d dug that spring) when Nibble came loping back again. And he was the messiest rabbit you ever heard of. And so cross and disgusted! “That bad baby!” he complained, beginning to clean the mud spots off his white shirt front. “He wouldn’t do anything I told him to. And then, the very first time I wasn’t looking, he danced in a puddle and splashed it all over me. From whiskers to—” he craned his neck about to look—“to tail! He all but drowned me!” “You don’t have to tell me that,” said Doctor Muskrat, and his fat sides were shaking with laughter. “I’ve eyes to see with. You’re as wet as ever you were when I fished you out of that pond there.” For you remember how Nibble tumbled right into the water he was so frightened the first time he ever saw the kind old muskrat. “And then,” Nibble went on indignantly, “the impudent little scamp sniffed his little turned-up nose at me because I was spluttering.” “You can’t expect a calf to be born with manners, can you?” soothed Doctor Muskrat, “’specially if it belongs to the Red Cow. But, as I told her, that’s the most remarkable youngst——” He flattened his ears, ready to dive, for a shadow came swooping down and he was expecting the Marsh Hawk back any day. But it was only Chaik the Jay. “Hello,” he piped. “Who was she and what did you tell her?” And he pounced on an acorn that was half-buried in the ground. “The Red Cow,” answered Doctor Muskrat, “has a little new calf who’s the most remarkable youngster I’ve ever seen.” And he was
  • 55. going to tell Chaik all about it, only—— Didn’t Nibble Rabbit just interrupt and tell it all himself? Just didn’t he? He was that puffed up because he was the first one to see it that he couldn’t wait. He described, how bright its little eyes were, and how it wriggled its tail like Chatter Squirrel does when he’s in a temper, and—everything there was to tell about that Red Cow’s red baby with the white star in his forehead and the turned-up nose. And all the time Nibble was forgetting to clean his fur. And the mud spots showed worse than ever as the wind dried them. But Nibble was too busy talking about that very same bad little Beast who had splashed them on him. Chaik was preening and tucking in his feathers every once in a while. He didn’t have his new spring coat yet, so he was very particular over his old one. Presently he noticed Nibble. “By the Worm in the Acorn, Rabbit, what’s happened to you?” he wanted to know. Do you think Nibble would tell on that Red Cow’s bad baby? Not at all. He just said, “Oh, I wasn’t looking—you don’t know what the walking is this spring.” Then he got very busy with his mud spots and Chaik flew away. “Hm,” giggled the doctor. “What do you really think of the Red Cow’s calf, what you told me about it or what you told Chaik?” “I mean,” said Nibble shamefacedly, “that I’m going up to see it to-morrow morning.” And off he hopped to his bed. He woke up early, early, before the darkest night had begun to melt into the gray of dawn. He yawned sleepily and rolled over. My, but that hole of his was warm and comfortable! Suddenly he jumped up and began to scrub his face with his paws. In about three minutes he was down by the pond, thumping for Doctor Muskrat. And weren’t the doctor’s eyes all sleepy when he poked his head out of the water? “Ouf,” he shivered, “what do you want at this hour of the night? Spear me with an icicle, but this pond is cold!” (If one of the Woodsfolk is found frozen to death the saying is that he’s been speared by an icicle.)
  • 56. “Come along,” said Nibble. “I’m going up to the barn to see the Red Cow and her bad baby.” “What do you take me for?” snorted the old doctor. “Don’t you forget that Silvertip the Fox is living there! Gimlet the Woodpecker said so. I can’t run like you can and there isn’t any water for me to dive into.” “I forgot,” apologized Nibble. “Well, you just be careful,” warned the wise old beast, “and you come straight back and tell me about him.” So off went Nibble, creeping about among the puddles. He dove into the Brushpile for a minute because he heard two birds talking. But they were only little downy Mr. and Mrs. Screech Owl, smaller than Bobby Robin. “I tell you it’s too early for nesting,” one was saying. “Not if Silvertip keeps on leaving all that nice food for us in the fence corner,” insisted the other. “He scarcely eats half of what he catches, and chickens are the best eating in the world for our owlets. We wouldn’t have to do any hunting.” “So,” said Nibble to himself, “Gimlet was right. Silvertip’s catching Tommy Peele’s chickens.” He sniffed carefully about the haystack and, sure enough, there was a nice nest that smelled of Silvertip—it’s almost the same smell as the seeds of the “cranes-bill,” as the Woodsfolk call wild geranium. It was empty, so Nibble cocked an ear at the chicken coop. Sure enough, there was a tiny rustling in the straw. As he sat there listening he heard the scared shout of a pullet, “Squa-awk! Squa-a—” and that was all. Silvertip had throttled her. Bounce! Down he came from the perch and slam! Out he slipped through the little back door his snoopy nose had learned how to open. But Nibble didn’t dare call Watch for fear Silvertip would hear him.
  • 57. Silvertip trotted past with the poor chicken hanging from his jaws.
  • 58. CHAPTER VI A GAME OF TAG IN TOMMY’S BARN You know about Nibble Rabbit. First he’s scared and then he’s curious. He was scared when he heard Silvertip catch the pullet. And he was still more scared when Silvertip trotted past in the mist, splashing softly in the puddles, with the poor chicken hanging from his jaws. But when Silvertip suddenly stopped and sniffed Nibble’s own footprints by the haystack, he was the scaredest little rabbit in all the fields and woods and the barnyard, too. Just the same he could see Silvertip say to himself, “It’s too wet to follow that trail. I’ll keep an eye out for bunnies around here as well as birds.” And Nibble said to his own self, “Bunny, that fox will have to do some looking.” Then Silvertip picked up the chicken and trotted on. Of course Nibble took a long breath when he had gone. That gave him time to grow curious. “I wonder which fence-corner those greedy little Screech Owls said he hid his food in?” he thought. “Watch would like to know.” So he peeked around the end of the stack and listened. Silvertip was away out of sight in the mist, but his feet went splashing off to the very corner of the Broad Field, where he used to sleep under some elderberry bushes. Yes, and sometimes he’d catch the birds who came there for berries. Oh, that Silvertip was certainly clever. “Now,” Nibble thought, “it’s safe for me to hunt for the Red Cow.” She wasn’t in the milking barn, but he could hear her baby, not very far away, calling his mother to get up and give him his breakfast. And the more he listened to that naughty little calf the more he wanted to see it again. So he crept down the line of scary, switchy tails, past the very last one. Then he came to a narrow lane, all
  • 59. sprinkled with dried clover-leaves. Pretty soon he had to squeeze under a door into another part of the barn. It was much brighter than the milking barn, because there was a hole in the wall at the far end. There were three box stalls, and he could hear the little calf in the last one. He hopped up on a bale of straw and ran along the top of the partition until he could look in and see him. There that naughty little beast had got tired of calling his mother and bunting her, so now he was trying to kick her. And Nibble thought he was cunninger than ever. Of course the Red Cow was pleased to see him, and full of talk. But Nibble was getting curious again. After a while he said, “Red Cow, I can see the trees moving outside, but there isn’t any wind in here. Why is that?” “Why, I never thought about it,” said the Red Cow. You remember she was always a little bit stupid. “I’m going to find out,” said Nibble. He hopped carefully along the partition to the window. And if ever a rabbit looked foolish, it was Nibble when he snubbed his twitchy nose against it. He was puzzled. None of the Woodsfolk could imagine such a thing as window glass. “What is it?” asked the Red Cow, wagging her big ears. “Ice,” guessed Nibble. “No, it’s not, either.” He was trying to taste it with his licky little tongue that he uses to wash his shirt front. “It doesn’t taste like the drops that freeze into my fur and it isn’t wet. But it’s cold——” And right then he learned some more about it. For you know Silvertip had seen the bunny’s footprints. “Chickens are all right,” thought the bad fox to himself as he trotted along, “but I’d a great deal rather have a nice tasty mouthful of rabbit.” So he hid the pullet and came galloping back to find Nibble. It wasn’t long before he saw the bunny’s trail going into the door of the milking barn, and he could smell plainly on the dry wood floor exactly where Nibble had gone. So Silvertip went sniffing quietly down the long aisle behind the row of cows. But they smelled him.
  • 60. “Help! Watch! Wolves! Wolves! Help!” they bawled. And they all tried to kick him. Now Silvertip was afraid to run out past their heels, so he had to follow Nibble’s trail under the door into the barn, where the box stalls were. And there he saw Nibble, perched on top of the partition, sniffing at the window with his back turned. Up jumped Silvertip on to the straw bale. Down jumped Nibble into the stall beside the Red Cow. “Arh,” whimpered Silvertip excitedly, and jumped after him. You never heard such a commotion. For the Red Cow began to roar and aim her horns at the fox. And Silvertip had to do some lively dodging. He’d just managed to scramble back on the partition when Watch came squeezing under the door. There wasn’t another place for the fox to turn so he ran straight for the window. “Wouw!” he whimpered as he hit it. But it was too late to stop. “Crash!” he went right through it and landed plump on the floor of a wagon that stood beneath it. Then he went galloping off to the woods as fast as he could go, holding up first one foot and then the other, for he couldn’t make up his mind where he was hurt the most. And his nose felt as if a bee had lit on it, and his eyes were so bunged up he could hardly see where he was going, and he had a new slit in the ear Mrs. Hooter had nipped—he was pretty badly damaged. And he was grinding his teeth and blaming poor Nibble Rabbit for every bit of it. For no one who thinks himself as clever as Silvertip can get into trouble without finding some way to think somebody else made him do it. “Aourgh!” barked Watch excitedly. And then of course Nibble knew he was perfectly safe, and he wanted to come out from under the Red Cow’s manger, where he had hidden, to see what was happening. But the naughty little calf was so excited he was dancing around and bunting at everything in sight. His mother had to give him some more breakfast before he’d stand still a single minute.
  • 61. There was Nibble, perched on top of the partition. By that time Silvertip was away off down the Pasture and Watch had squeezed under the door again. He was bound to catch that fox, but he knew more than to go jumping through windows after him. So Nibble just hopped up on the manger and from there onto the high partition and stretched out his inquisitive nose where the glass had been. There wasn’t much left for him to snub it against, I can tell you. And the wind blew through it so hard that it laid his ears flat back.
  • 62. “What is it?” demanded the Red Cow. She was learning to be curious, too, and that’s the first step to being wise and sensible. “It’s awfully hard,” Nibble answered. “I can bite ice, but I can’t bite this.” Just then who should open the door but Tommy Peele with the Red Cow’s breakfast. Right away he saw the glass was broken. But he wasn’t angry at all. He just said, “Did you do that?” But he picked up every bit that had fallen inside so folks wouldn’t cut their feet on it, and then he went around to pick up what was outside, too. And he found some blood and a big tuft of Silvertip’s hair on the wagon-box. “Phew!” he whistled. “Bunny, this fur isn’t any of yours—nor that footprint, either! You just wait until school is out and Watch and I’ll just see about this!” He hadn’t any time to do it then. For he had to stuff the Red Cow’s manger full of hay and hurry fast to get to the schoolhouse before the bell rang. “Have some, Nibble,” she lowed politely. And the bunny didn’t need a second invitation. His twitchy nose had been wiggling pretty fast from the first minute he smelled that delicious clover.
  • 63. CHAPTER VII THE WHITE COW BEGINS A STORY If the smell of that delicious hay in the Red Cow’s manger made Nibble’s nose go fast, the taste of it made his hungry little jaws go still faster. And the Red Cow was just about as busy as he was. Her big teeth wouldn’t move quite so quickly, but she could take bigger bites to make up for lost time. They were still eating when he heard a loud snort just outside. So he jumped up on the windowsill again to be sure who it was. “Hello, Rabbit,” came the White Cow’s nice fluty voice as she saw his whiskers in the window. “I told you you’d come back again.” “Oh, the Red Cow’s got such a cunning calf in here I just have to come,” he laughed. “She has, has she?” mooed the White Cow. “I’d like to see it myself.” She was a motherly old beast, so she really did love babies. “Is it all right? That wolf who ran through the milking barns has been around here—I can smell him. Calves are what they always come for.” “That was only Silvertip the Fox,” he chuckled. “He’s gone!” Still the White Cow kept shaking her head and snorting. “He’s no business here. He’s a wolf, and it’s plain against the compact.” “What compact, please, Madame Snowflake?” lowed the Red Cow. “Why, the compact between Cows and Man,” she answered. “You know Man used to hunt us. It must have been dreadful, for one man is worse than a whole pack of wolves-” “Exactly what Doctor Muskrat says!” exclaimed Nibble. “Well, it’s true,” she asserted. “Cows are all right so long as they keep all together. But you can’t have little new wobbly babies in a herd because we’re so near-sighted someone would be sure to step
  • 64. on them. So the mothers used to go off and hide them until they grew strong enough not to let themselves get stepped on. And the wolves and the men would watch out for them. No matter how careful the cows were someone would be sure to find them. Long before they came, the mothers would get all scary and unhappy just thinking about it.” “I felt just that way!” gasped the Red Cow. “Didn’t I, Nibble?” “Well, after a long time Man made a compact with the cows. He promised that if they’d live with him and give him milk and plough his fields and let him take the meat of certain ones, not the young heifers or the mothers, he’d keep the wolves away from them.” “How did that happen?” asked Nibble excitedly, for he guessed it was one of those tales of the First-Off Beginning of Things. And sure enough, the White Cow began, “Well, as I said, both Man and wolves hunted the cows in the First-Off Beginning. That was bad enough. But when Man made friends with the dogs, who were really wolves, it was worse yet. They both knew all the tricks between them. “There was a river wandering through the plain where the cows used to feed, and it had a rocky island standing up in the middle of it. The island was hollow as a cup and full of brush and grass, and there was only one crack in the rocks where a cow could just squeeze through to get into it. It was a secret among the cows, who only went there to raise their calves, and they were careful to walk a long way in the water to hide their trails before they crossed over to it. So the wolves would never have found it. But a man did. “He was hunting cows. So were a pack of wolves, and they saw he had only one dog, so they decided to hunt him instead. They say a man is very good eating. So he ran for the island. Because he knew if he could climb high up on the tall rocks they couldn’t climb up after him. He had to take his dog by the scruff of the neck to help him. And of course when he got up high he could see everything—the two cows who were grazing in the middle of the island and the narrow passage between the rocks, and the wolves
  • 65. running around and around looking for a place where they could get in. “The cows couldn’t see the wolves, but they could hear them. So one of them, who was an old cow and very wise, galloped over to the passage. And when the wolves got there she was stopping the way with her sharp horns. “I don’t know how long she could have stayed there, for there were a great many wolves and only one cow, but the man was wiser yet. He saw a big tippy boulder that he could roll down to block the passage so nobody could possibly get in. And he gave it a big shove. Smash, it went down right in the middle of the wolves! It killed the leader and another wolf, and the rest got scared and ran away. “So did the cow, for the man’s dog started right after her. But the man called him back. ‘Come here!’ he called. ‘Stop that, you foolish thing. The wolves would have picked our bones if she hadn’t helped us. That’s one cow you can never kill.’ “The dog came back with his tail between his legs, grumbling to himself. ‘This is very queer. It’s the first time in all my life I was told not to kill anything.’ And of course the cow heard him. And it set her thinking.”
  • 66. CHAPTER VIII HOW THE MAN’S WIFE MADE THE COMPACT WITH THE COWS The White Cow stopped talking quite as though she had finished her story. But Nibble Rabbit and the Red Cow, who were listening with all their ears, both broke out: “Please, Mrs. Snowflake, you haven’t said a word yet about the compact!” “Pickery thistles!” she exclaimed. “So I haven’t. I was just thinking about it instead. Well, the man was in the middle of that little hollow island with the high rocks all around it, and so were the cows. The dog was growling because he couldn’t kill the cow, and the cow was wondering why the man wouldn’t let him. But most of all she was wondering how quickly she and her calf would starve because that stone blocked up the passage. “The man was thinking that, too. For the cow had saved his life by keeping out the wolves; that made him in debt to her. And if a man was careless about his debts he was sure to be dreadfully unlucky. Either he had to roll away that stone so the cow could go over to the plains to graze—and he knew he couldn’t do that—or he had to bring the grass to her. “Bright and early next morning he went to bring the grass to feed that cow. He found it was lots of trouble, especially since he didn’t have his wife there to help him. So he decided to bring her. “He told her how nice and safe it was in the middle of that rocky island until she got quite delighted at the idea of living there. So she packed their belongings on her back, slung their baby in front of her, and started out. She waded the stream all right, but she stopped at the big rock which blocked up the passage. “‘I won’t stay here at all unless you take that out of there,’ she said. ‘It’s too inconvenient.’
  • 67. “So of course he just had to. And when it comes right down to ‘having to’ a man can do almost anything. But he had a terrible time. He heaved and clawed and shoved and rolled until his fingers and arms were sore. Then he picked up a stick, because it was easier to handle—and he learned how to pry that stone out of the passage. “In walked his wife and began to settle their new home. Out walked the cows, and over they went to the plain to pick their own grass, but they left their calves hidden on the island. So, after they had finished feeding, back they came. “Then the man took his stick and pried the rock into the passage again for fear the wolves would come back. And his wife stared at the cows and the cows stared at his wife, but still they didn’t make any compact.” Nibble Rabbit and the Red Cow were both fairly stamping their feet with impatience because the White Cow wouldn’t hurry right along with her story. But she brought a big wad of cud all the way up her long neck and stood there chewing it while she thought things over. Finally she swallowed it and went on. “I told you the man learned to use the great stone for a gate to the narrow passageway where the cows squeezed through. But I didn’t tell you how angry the wolves were about that. “They were simply raging. Night after night they gnashed their jaws and howled around those rocks, but their claws wouldn’t climb them. And the man’s dog would sit up on top and shout insults at them. And the two cows would snuggle together in the brush with their calves between them and say, ‘Those wolves would have eaten us long ago if the man hadn’t been here.’ “They got very used to the man and his family. They didn’t walk ’way round his fire any more, or make eyes at his wife, and the calves got very friendly with his baby. But his wife used to look hard at them. ‘It’s all very well to take care of the cow who saved your life,’ she’d say to the man, ‘but how about that other one?’ “‘Well, what about her?’ he’d answer. ‘She isn’t any trouble.’ “‘She ought to pay for being taken care of,’ insisted his wife. ‘It’s all very well for this year, but next year these calves will be grown up
  • 68. and there will be new ones and we’ll be all cluttered up with cattle.’ “She thought and thought. At last she caught up her biggest clamshell and walked down into the thicket where the cows stood. And the dog went with her. ‘Old Cow,’ she said, ‘you can live with us for ever and ever because you stopped the passageway with your horns when the wolves were trying to get in to kill my husband. Young Cow, you will have to pay something if you’re going to live with us.’ And with that she tried to milk the young cow into her clamshell. “The young cow didn’t like it a little bit. But she was afraid of the dog, and besides the old cow argued, ‘You have milk to spare, and you’ll never have any place as safe as this. Let me talk to her.’ “So the young cow gave in and let herself be milked. But the old one said to the woman: ‘We’ll stay with you and give you milk so long as you see we get food and water and protect us from the wolves. But the minute you don’t we’ll go off and be wild again, and you’ll be no better off than you were before.’ “‘Agreed,’ said the woman. ‘The dog will be our witness.’ “So that was the beginning of the compact. The cows settled down to live with the man and his family. But after the woman was gone the wise old cow said comfortably, ‘It’s spring now. She doesn’t think how much trouble it will be to feed us through the winter.’” “Wasn’t that old cow clever!” exclaimed Nibble admiringly. The White Cow snorted. “She was wise. But that woman was wiser. She knew that if she waited long enough there would be cattle on that island who hadn’t any milk, so she and the man could bargain some more with them. They had to carry loads and pull ploughs; they even had to let the man kill certain ones. They didn’t like that a little bit, but the wise old cow argued, ‘It’s better than being hunted by both wolves and men.’ So they finally gave in. It was really a good bargain for us,” finished the White Cow thoughtfully, “but it was a better one for the man. After he learned to build barns as safe as that island he gave up hunting.”
  • 69. CHAPTER IX HOW A BUNNY UNDERTOOK TO HUNT A FOX Madame snowflake swished her tail thoughtfully for a moment; then she went back to chewing her cud as a sign that her story was all done. “My horns!” exclaimed the Red Cow. “That’s awfully interesting.” “Yes,” drawled the story-teller. “But can’t you see how worrisome it is? If Tommy Peele lets wolves go galloping through this barn we’ll have to go wild again. It’s in the compact. That’s what I’ve been trying to explain.” “Noo-oo-oo,” the Red Cow moaned. “I don’t want to go wild. I won’t go wild again. I’ve been wild once, and I like being Tommy Peele’s tame cow ever so much better.” “Nonsense!” interrupted Nibble Rabbit, sitting up very straight. “It hasn’t anything at all to do with you cows. Silvertip’s no more of a wolf than Watch is. Besides, I’m the only one he was chasing. He won’t come back again unless I do, and I won’t come until there isn’t any Silvertip to chase me.” “Hoo-oo,” teased the White Cow. “What can you do to Silvertip?” “Wait and see,” said Nibble. And off he set. But as he ran he said to himself, “Silvertip’s very big and clever—whatever can I do to him?” For a while he was just about the most thoughtful bunny that ever flopped an ear. He’d made the White Cow a great big promise, one no grownup rabbit would ever have thought of. And he had to have help about it. He was pretty glad, I can tell you, when he saw Watch scouting about the pasture with his nose to the ground.
  • 70. “Have you found where Silvertip went to?” Nibble asked when the big dog stopped to speak with him. “No,” said Watch in a discouraged tone. “There was a mist this morning and it’s washed away all the scent. But what do you want of Silvertip?” “I’ve got to help you catch him,” murmured Nibble. “You!” exclaimed Watch. “You must be as crazy as a chickadee! Has any thing bitten you?” You know dogs are terribly afraid of being bitten by a crazy beast—it makes them go mad, too. “No. But—but I promised the White Cow that I wouldn’t come back to the barn while Silvertip was alive to chase into it after me— and I won’t stay away from the Red Cow’s baby for ever and ever. Something’s got to happen to Silvertip.” “I wouldn’t want him chasing me if I were you,” Watch agreed. This sounded more sensible. “But I don’t see what the White Cow has to do with it.” “She says Silvertip is really a wolf,” Nibble explained, “and if Tommy Peele lets wolves come right into his barn, whether it’s calves or rabbits they’re hunting, the cows will have to go wild again. That’s in the compact between cows and man in the First-Off Beginning.” “Wurr-r-r!” Watch growled thoughtfully. “So it is. But that’s my trouble, and the cow’s and Tommy’s. It hasn’t anything to do with you.” Suddenly Nibble remembered something and quoted: “By dusk and by dawn you shall travel alone. And all troubles are yours excepting your own. That’s my fortune. The stars told it to Doctor Muskrat the day I left home.” “I understand,” Watch nodded wisely. “Well, the trouble about all this is that I can’t explain it to Tommy. And we need him. What can you do to Silvertip—except give him a stomachache from eating too much rabbit, eh?”
  • 71. “I can see where he is and what he does. I know how he gets into the chicken coop and where he hid the pullet he stole this morning and the feathers from all the rest he’s been stealing.” “How—when—where!” barked Watch excitedly. “We don’t have to tell that to Tommy—we can show it to him. Quick, Nibble! How did Silvertip get into the chicken coop? Tommy’ll be home from school any minute.” So Nibble took him around to the little back door. “That fox is certainly clever,” sniffed Watch. “He’s gnawed the hook right off. I’ve smelt him around here dozens of times, but I never thought of looking inside of the coop for him.” Then he lifted it with his nose, just as Silvertip had done, but he was too big to crawl in. It was Nibble who squeezed through and took a hop on to the soft straw of the chicken coop floor. Then he sat up to sniff around. The hens were scratching busily, but the rooster was dozing off a full crop on his perch. Nibble poked his nose into a box of feed and the bird next to him went, “Cut, cut!” That woke the rooster. He opened his eye and caught sight of Nibble’s whiskers. “Er—er—err, I’m Chanticleer!” he crowed. “And you’re the rascal who stole my beautiful young wife, Specklefeather, this morning! You’re the one who took Stripedwing, the best setting hen ever a rooster owned, and dear little red-wattled Minorca—and all the rest who’ve been snatched from my perches. Your time has come! I’ll show you——” and he flapped down and began to peck poor Nibble and kick him with those long spurs roosters wear on their legs.
  • 72. Nibble visits the chicken coop. “Wait a minute, wait a minute!” Nibble cried. But the rooster wouldn’t listen. Then a voice behind Nibble called, “Here, here,” and he darted under the perches and squeezed into a dark nest beside a hen. “There,” she clucked. “That old bully never comes here. It isn’t proper for a rooster to come into the nesting corner. Poor Stripedwing. She used to set in here most of the time because he was so cruel to her. And he killed our son because Minorca was in love with him. I wish the fox had taken him.”
  • 73. Nibble peeked out again and saw the rooster strutting around as though he’d really done something grand, calling on the hens to admire him. And now he could hear Watch shouting, “Come along, Tommy—come quick!” In a minute more he was barking outside the front door, and Tommy opened it. “What’s the matter?” asked Tommy. Out hopped Nibble Rabbit. “However did you get in here?” gasped the little boy. And with that Nibble slipped through the little back door as neat as you please. Maybe Tommy didn’t whistle! And maybe he wasn’t still more surprised when he saw the hook all gnawed! But maybe he wasn’t maddest of all when Nibble and Watch took him across the field to Silvertip’s fence corner, all full of feathers, with poor dead Specklefeather lying in the middle of it! “The fox!” Tommy exclaimed. “Old chicken thief; he ought to be hunted with a gun!” “That’s all right,” Watch wagged his tail. “Now Tommy’ll find the gun and a man to shoot it, but we’ll have to find Silvertip so they can shoot him. I’ll sleep in the haystack and watch the barn, and you see if he’s hidden in the woods.” So Nibble cocked his own little puffy tail and laid back his ears and scuttled through the cornfield. Because the first one he meant to ask was Doctor Muskrat. And it didn’t take much thumping to wake the doctor. “My whiskers, but I’m glad to see you,” said the nice old beast as soon as he got his nose out of the water. “I was afraid that fox had really caught you. He came down here for a drink early this morning. He was feeling pretty sick, but he said he wasn’t going to do another thing until he’d pulled your long ears out by the roots and made a meal of you.” “Well, he doesn’t want to find me any more than I want to find him,” said Nibble. And he told how Silvertip had followed him into the barn and jumped smash through the window, and what trouble that made for the cows, and the way he’d killed Tommy’s chickens, and how angry Tommy was about it.
  • 74. “Shoot him? I wish they would.” Doctor Muskrat agreed. “He’s the worst beast in all the woods and fields, and we’ve plenty more to look out for—Slyfoot the Mink and the Marsh Hawk are back, and Grandpop Snapping Turtle is out again—but you’ll have to be mighty careful. You dig yourself a root and stay hidden while I see what the birds know about him.” So Doctor Muskrat asked every bird who came down to drink if he’d keep an eye out for Silvertip. That was a great many, too, for whole clouds of them were coming north on every south wind. But they were all so busy about courting and nesting it was three days before Doctor Muskrat had any news. Late in the evening a whippoorwill came dipping down like a great feathery moth and called softly: “Doctor Muskrat!” Then he perched on the doctor’s house and whispered: “Silvertip’s living in the hollow log that shadows my last year’s nest. He’s still too sick to hunt anything but frogs and tadpoles and the eggs of us poor ground birds, but the minute he can gallop he’s going to get that rabbit. He lies there growling and swearing about him.” Nibble couldn’t hear what the whippoorwill said. And that was lucky, because he was lying very still in the Quail’s Thicket with those screech owls perched right above him.
  • 75. CHAPTER X THE WICKED PLOT OF THE BAD LITTLE OWLS As soon as the whippoorwill had finished whispering the news, about where Silvertip was hiding, he flew off so quietly that even the doctor couldn’t hear him. Then the wise old beast raised his queer, thin call, almost like a whistle, to tell Nibble Rabbit he was wanted, and swam quite as quietly to the place in the bulrushes by the pond where they always met. But no Nibble came. Nibble Rabbit was still hiding in the Quail’s Thicket, listening to Mr. and Mrs. Screech Owl, who were perched right above him. “That bird’s telling him about Silvertip,” said one. “If it had been any other bird in the woods he’d have spoken so we could overhear him.” “I wish he had,” said the other. “We’ve picked that last hen so clean we’ll have to hunt for ourselves if we can’t find him. I wonder what that muskrat wants of him. He’s been asking every bird who came down to drink for the last three days. I heard Chaik the Jay talking to Chewee the Chickadee about it just when I was going to sleep this morning.” “What did they say?” demanded Mrs. Screech Owl. The lady owl is always the more thoughtful. They both live in trees. Silvertip never bothers them. “I didn’t understand,” said her mate. “Chaik was insisting that they must all hunt hard for Silvertip. He said that it concerned every good friend of Tommy Peele’s.” “You pinfeathered idiot!” she exclaimed. “Why didn’t you tell me that before? That explains why Tommy Peele and his dog were sniffing about Silvertip’s fence corner. And that rabbit was with them.
  • 76. He’s at the bottom of all this. Something’s wrong there. I never knew a wild rabbit to be friends with a dog in all my life. If he’ll do that he’ll do anything. Silvertip must be warned. We can’t let anything happen to him. Besides, think how much he could do for us if he felt grateful.” “Grateful? Not much. A fox is never grateful. But he’d know we were useful and that amounts to the same thing. I wonder why that rabbit doesn’t answer Doctor Muskrat?” and Mr. Screech Owl flew cautiously over the doctor’s house in the middle of the pond. Back he came to where his wife was still thinking. “He must have meant that call for the whippoorwill,” he said to his mate. “He’s gone to bed.” “We must get some friend who lives on the ground to keep watch for us, too,” said the Lady Owl thoughtfully. “Only Silvertip has no friends. He’ll eat anybody.” “Excepting old Foul Fang the Rattlesnake,” said Mr. Screech Owl. “We could buy Foul Fang’s service for a mouse a day. I’ll just do that, and you go up to the house, not the barn, mind, and see if you can get a word with that grandson of Ouphe the Rat who lives there. Silvertip’s never hunted him. By the kitchen door—now flutter!” And away they went. But Nibble waited until he was perfectly sure they had gone before he crept down to talk with Doctor Muskrat in the bulrushes. And he was a pretty trembly little rabbit. He hopped very carefully, gliding from shadow to shadow like a fieldmouse. And the doctor never moved when Nibble Rabbit slipped in beside him; he was listening to the stars as they danced in the pool just exactly the way he had done the night they told him Nibble’s fortune. He was muttering: “Let him who is both young and wise Beware the killer with lidless eyes. “Yes, that’s all I can make out of it,” said the old doctor slowly. “Now what does that mean, I wonder?”
  • 77. Welcome to Our Bookstore - The Ultimate Destination for Book Lovers Are you passionate about books and eager to explore new worlds of knowledge? At our website, we offer a vast collection of books that cater to every interest and age group. From classic literature to specialized publications, self-help books, and children’s stories, we have it all! Each book is a gateway to new adventures, helping you expand your knowledge and nourish your soul Experience Convenient and Enjoyable Book Shopping Our website is more than just an online bookstore—it’s a bridge connecting readers to the timeless values of culture and wisdom. With a sleek and user-friendly interface and a smart search system, you can find your favorite books quickly and easily. Enjoy special promotions, fast home delivery, and a seamless shopping experience that saves you time and enhances your love for reading. Let us accompany you on the journey of exploring knowledge and personal growth! ebookgate.com