| Preface |
|
xvii | |
| Acknowledgments |
|
xix | |
| About this book |
|
xx | |
| About the authors |
|
xxii | |
|
|
|
1 | (8) |
|
1.1 Why you can't afford to ignore PowerShell |
|
|
1 | (2) |
|
|
|
2 | (1) |
|
|
|
2 | (1) |
|
1.2 And now, it's just "PowerShell" |
|
|
3 | (1) |
|
1.3 Is this book for you? |
|
|
3 | (1) |
|
|
|
4 | (2) |
|
|
|
4 | (1) |
|
|
|
5 | (1) |
|
|
|
5 | (1) |
|
|
|
5 | (1) |
|
|
|
5 | (1) |
|
|
|
5 | (1) |
|
1.5 Setting up your lab environment |
|
|
6 | (1) |
|
1.6 Installing Windows PowerShell |
|
|
7 | (1) |
|
|
|
8 | (1) |
|
1.8 Being immediately effective with PowerShell |
|
|
8 | (1) |
|
|
|
9 | (11) |
|
|
|
9 | (6) |
|
|
|
11 | (2) |
|
The Integrated Scripting Environment |
|
|
13 | (2) |
|
2.2 It's typing class all over again |
|
|
15 | (2) |
|
2.3 Common points of confusion |
|
|
17 | (1) |
|
2.4 What version is this? |
|
|
17 | (1) |
|
|
|
18 | (2) |
|
|
|
20 | (17) |
|
3.1 The help system: how you discover commands |
|
|
20 | (2) |
|
|
|
22 | (1) |
|
|
|
23 | (1) |
|
3.4 Using help to find commands |
|
|
24 | (2) |
|
3.5 Interpreting the help |
|
|
26 | (7) |
|
Parameter sets and common parameters |
|
|
26 | (2) |
|
Optional and mandatory parameters |
|
|
28 | (1) |
|
|
|
28 | (2) |
|
|
|
30 | (3) |
|
|
|
33 | (1) |
|
3.6 Accessing "about" topics |
|
|
33 | (1) |
|
3.7 Accessing online help |
|
|
34 | (1) |
|
|
|
34 | (2) |
|
|
|
36 | (1) |
|
|
|
37 | (14) |
|
4.1 Not scripting, but running commands |
|
|
37 | (1) |
|
4.2 The anatomy of a command |
|
|
38 | (1) |
|
4.3 The cmdlet naming convention |
|
|
39 | (1) |
|
4.4 Aliases: nicknames for commands |
|
|
40 | (2) |
|
|
|
42 | (2) |
|
Truncating parameter names |
|
|
42 | (1) |
|
Using parameter name aliases |
|
|
42 | (1) |
|
Using positional parameters |
|
|
42 | (2) |
|
4.6 Cheating a bit: Show-Command |
|
|
44 | (1) |
|
4.7 Support for external commands |
|
|
44 | (4) |
|
|
|
48 | (1) |
|
4.9 Common points of confusion |
|
|
49 | (1) |
|
|
|
49 | (1) |
|
|
|
49 | (1) |
|
|
|
50 | (1) |
|
|
|
51 | (12) |
|
|
|
51 | (2) |
|
5.2 Understanding how the filesystem is organized |
|
|
53 | (2) |
|
5.3 Understanding how the filesystem is like other data stores |
|
|
55 | (1) |
|
5.4 Navigating the filesystem |
|
|
55 | (2) |
|
5.5 Using wildcards and literal paths |
|
|
57 | (1) |
|
5.6 Working with other providers |
|
|
58 | (3) |
|
|
|
61 | (1) |
|
|
|
62 | (1) |
|
|
|
62 | (1) |
|
6 The pipeline: connecting commands |
|
|
63 | (13) |
|
6.1 Connecting one command to another: less work for you |
|
|
63 | (1) |
|
6.2 Exporting to a CSV or an XML file |
|
|
64 | (5) |
|
|
|
65 | (1) |
|
|
|
66 | (1) |
|
|
|
67 | (2) |
|
6.3 Piping to a file or a printer |
|
|
69 | (1) |
|
|
|
70 | (1) |
|
6.5 Using cmdlets that modify the system: killing processes and stopping services |
|
|
71 | (1) |
|
6.6 Common points of confusion |
|
|
72 | (2) |
|
|
|
74 | (1) |
|
|
|
75 | (1) |
|
|
|
76 | (13) |
|
7.1 How one shell can do everything |
|
|
76 | (1) |
|
7.2 About product-specific "management shells" |
|
|
77 | (1) |
|
7.3 Extensions: finding and adding snap-ins |
|
|
78 | (2) |
|
7.4 Extensions: finding and adding modules |
|
|
80 | (2) |
|
7.5 Command conflicts and removing extensions |
|
|
82 | (1) |
|
7.6 On non-Windows operating systems |
|
|
83 | (1) |
|
7.7 Playing with a new module |
|
|
83 | (2) |
|
7.8 Profile scripts: preloading extensions when the shell starts |
|
|
85 | (1) |
|
7.9 Getting modules from the internet |
|
|
86 | (1) |
|
7.10 Common points of confusion |
|
|
87 | (1) |
|
|
|
87 | (1) |
|
|
|
88 | (1) |
|
8 Objects: data by another name |
|
|
89 | (12) |
|
|
|
89 | (1) |
|
8.2 Understanding why PowerShell uses objects |
|
|
90 | (2) |
|
8.3 Discovering objects: Get-Member |
|
|
92 | (2) |
|
8.4 Using object attributes, or properties |
|
|
94 | (1) |
|
8.5 Using object actions, or methods |
|
|
94 | (1) |
|
|
|
95 | (1) |
|
8.7 Selecting the properties you want |
|
|
96 | (1) |
|
8.8 Objects until the end |
|
|
97 | (2) |
|
8.9 Common points of confusion |
|
|
99 | (1) |
|
|
|
99 | (1) |
|
|
|
100 | (1) |
|
|
|
101 | (22) |
|
9.1 The pipeline: enabling power with less typing |
|
|
101 | (1) |
|
9.2 How PowerShell passes data down the pipeline |
|
|
101 | (1) |
|
9.3 Plan A: pipeline input ByValue |
|
|
102 | (4) |
|
9.4 Plan B: pipeline input ByPropertyName |
|
|
106 | (5) |
|
9.5 When things don't line up: custom properties |
|
|
111 | (3) |
|
9.6 Parenthetical commands |
|
|
114 | (1) |
|
9.7 Extracting the value from a single property |
|
|
115 | (6) |
|
|
|
121 | (1) |
|
|
|
122 | (1) |
|
|
|
122 | (1) |
|
10 Formatting---and why it's done on the right |
|
|
123 | (16) |
|
10.1 Formatting: making what you see prettier |
|
|
123 | (1) |
|
10.2 Working with the default formatting |
|
|
124 | (3) |
|
|
|
127 | (1) |
|
|
|
128 | (1) |
|
10.5 Formatting wide lists |
|
|
129 | (1) |
|
10.6 Creating custom columns and list entries |
|
|
130 | (3) |
|
10.7 Going out: to a file, a printer, or the host |
|
|
133 | (1) |
|
10.8 Another out: GridViews |
|
|
133 | (1) |
|
10.9 Common points of confusion |
|
|
133 | (4) |
|
|
|
133 | (2) |
|
One type of object at a time, please |
|
|
135 | (2) |
|
|
|
137 | (1) |
|
10.11 Further exploration |
|
|
137 | (1) |
|
|
|
138 | (1) |
|
11 Filtering and comparisons |
|
|
139 | (9) |
|
11.1 Making the shell give you just what you need |
|
|
139 | (1) |
|
|
|
140 | (1) |
|
11.3 Using comparison operators |
|
|
140 | (2) |
|
11.4 Filtering objects out of the pipeline |
|
|
142 | (2) |
|
11.5 Using the iterative command-line model |
|
|
144 | (1) |
|
11.6 Common points of confusion |
|
|
145 | (1) |
|
|
|
145 | (1) |
|
|
|
146 | (1) |
|
|
|
146 | (1) |
|
|
|
147 | (1) |
|
|
|
147 | (1) |
|
|
|
148 | (5) |
|
|
|
148 | (1) |
|
12.2 Finding the commands |
|
|
148 | (2) |
|
12.3 Learning to use the commands |
|
|
150 | (1) |
|
12.4 Tips for teaching yourself |
|
|
151 | (1) |
|
|
|
152 | (1) |
|
|
|
152 | (1) |
|
13 Remote control: one-to-one, and one-to-many |
|
|
153 | (18) |
|
13.1 The idea behind remote PowerShell |
|
|
154 | (1) |
|
|
|
155 | (4) |
|
13.3 Using Enter-PSSession and Exit-PSSession for one-to-one remoting |
|
|
159 | (2) |
|
13.4 Using Invoke-Command for one-to-many remoting |
|
|
161 | (2) |
|
13.5 Differences between remote and local commands |
|
|
163 | (4) |
|
Invoke-Command vs. -computerName |
|
|
164 | (1) |
|
Local vs. remote processing |
|
|
165 | (1) |
|
|
|
166 | (1) |
|
13.6 But wait, there's more |
|
|
167 | (1) |
|
|
|
168 | (1) |
|
13.8 Common points of confusion |
|
|
168 | (1) |
|
|
|
169 | (1) |
|
13.10 Further exploration |
|
|
170 | (1) |
|
|
|
170 | (1) |
|
14 Using Windows Management Instrumentation and CIM |
|
|
171 | (14) |
|
|
|
172 | (1) |
|
14.2 The bad news about WMI |
|
|
173 | (1) |
|
|
|
174 | (3) |
|
14.4 Choose your weapon: WMI or CIM |
|
|
177 | (1) |
|
|
|
178 | (4) |
|
14.6 Using Get-Cimlnstance |
|
|
182 | (1) |
|
|
|
182 | (1) |
|
14.8 Common points of confusion |
|
|
182 | (1) |
|
|
|
183 | (1) |
|
14.10 Further exploration |
|
|
184 | (1) |
|
|
|
184 | (1) |
|
15 Multitasking with background jobs |
|
|
185 | (15) |
|
15.1 Making PowerShell do multiple things at the same time |
|
|
185 | (1) |
|
15.2 Synchronous vs. asynchronous |
|
|
186 | (1) |
|
15.3 Creating a local job |
|
|
187 | (1) |
|
|
|
188 | (1) |
|
|
|
189 | (1) |
|
|
|
189 | (3) |
|
15.7 Working with child jobs |
|
|
192 | (2) |
|
15.8 Commands for managing jobs |
|
|
194 | (2) |
|
|
|
196 | (1) |
|
15.10 Common points of confusion |
|
|
197 | (1) |
|
|
|
198 | (1) |
|
|
|
199 | (1) |
|
16 Working with many objects, one at a time |
|
|
200 | (16) |
|
16.1 Automation for mass management |
|
|
200 | (1) |
|
16.2 The preferred way: "batch" cmdlets |
|
|
201 | (1) |
|
16.3 The CIM/WMI way: invoking methods |
|
|
202 | (4) |
|
16.4 The backup plan: enumerating objects |
|
|
206 | (5) |
|
16.5 Common points of confusion |
|
|
211 | (3) |
|
Which way is the right way? |
|
|
211 | (1) |
|
|
|
212 | (1) |
|
|
|
213 | (1) |
|
|
|
213 | (1) |
|
|
|
214 | (1) |
|
|
|
214 | (2) |
|
|
|
216 | (12) |
|
17.1 Keeping the shell secure |
|
|
216 | (1) |
|
17.2 Windows PowerShell security goals |
|
|
217 | (1) |
|
17.3 Execution policy and code signing |
|
|
218 | (7) |
|
Execution policy settings |
|
|
218 | (4) |
|
|
|
222 | (3) |
|
17.4 Other security measures |
|
|
225 | (1) |
|
17.5 Other security holes? |
|
|
225 | (1) |
|
17.6 Security recommendations |
|
|
226 | (1) |
|
|
|
227 | (1) |
|
18 Variables: a place to store your stuff |
|
|
228 | (16) |
|
18.1 Introduction to variables |
|
|
228 | (1) |
|
18.2 Storing values in variables |
|
|
229 | (2) |
|
18.3 Using variables: fun tricks with quotes |
|
|
231 | (2) |
|
18.4 Storing many objects in a variable |
|
|
233 | (4) |
|
Working with single objects in a variable |
|
|
234 | (1) |
|
Working with multiple objects in a variable |
|
|
235 | (1) |
|
Other ways to work with multiple objects |
|
|
236 | (1) |
|
Unrolling properties and methods in PowerShell v3 |
|
|
237 | (1) |
|
18.5 More tricks with double quotes |
|
|
237 | (2) |
|
18.6 Declaring a variable's type |
|
|
239 | (2) |
|
18.7 Commands for working with variables |
|
|
241 | (1) |
|
18.8 Variable best practices |
|
|
242 | (1) |
|
18.9 Common points of confusion |
|
|
242 | (1) |
|
|
|
242 | (1) |
|
18.11 Further exploration |
|
|
243 | (1) |
|
|
|
243 | (1) |
|
|
|
244 | (9) |
|
19.1 Prompting for, and displaying, information |
|
|
244 | (1) |
|
|
|
245 | (3) |
|
|
|
248 | (1) |
|
|
|
249 | (2) |
|
|
|
251 | (1) |
|
|
|
252 | (1) |
|
|
|
252 | (1) |
|
|
|
252 | (1) |
|
21 Sessions: remote control with less work |
|
|
253 | (10) |
|
20.1 Making PowerShell remoting a bit easier |
|
|
253 | (1) |
|
20.2 Creating and using reusable sessions |
|
|
254 | (1) |
|
20.3 Using sessions with Enter-PSSession |
|
|
255 | (2) |
|
20.4 Using sessions with Invoke-Command |
|
|
257 | (1) |
|
20.5 Implicit remoting: importing a session |
|
|
258 | (2) |
|
20.6 Using disconnected sessions |
|
|
260 | (1) |
|
|
|
261 | (1) |
|
|
|
262 | (1) |
|
|
|
262 | (1) |
|
21 You call this scripting? |
|
|
263 | (13) |
|
21.1 Not programming, more like batch files |
|
|
263 | (1) |
|
21.2 Making commands repeatable |
|
|
264 | (1) |
|
21.3 Parameterizing commands |
|
|
265 | (2) |
|
21.4 Creating a parameterized script |
|
|
267 | (1) |
|
21.5 Documenting your script |
|
|
268 | (2) |
|
21.6 One script, one pipeline |
|
|
270 | (3) |
|
21.7 A quick look at scope |
|
|
273 | (1) |
|
|
|
274 | (1) |
|
|
|
275 | (1) |
|
22 Improving your parameterized script |
|
|
276 | (10) |
|
|
|
276 | (1) |
|
22.2 Getting PowerShell to do the hard work |
|
|
277 | (1) |
|
22.3 Making parameters mandatory |
|
|
278 | (2) |
|
22.4 Adding parameter aliases |
|
|
280 | (1) |
|
22.5 Validating parameter input |
|
|
281 | (1) |
|
22.6 Adding the warm and fuzzies with verbose output |
|
|
282 | (2) |
|
|
|
284 | (1) |
|
|
|
284 | (2) |
|
23 Advanced remoting configuration |
|
|
286 | (10) |
|
23.1 Using other endpoints |
|
|
286 | (1) |
|
23.2 Creating custom endpoints |
|
|
287 | (4) |
|
Creating the session configuration |
|
|
288 | (1) |
|
|
|
289 | (2) |
|
23.3 Enabling multihop remoting |
|
|
291 | (1) |
|
23.4 Digging deeper into remoting authentication |
|
|
292 | (2) |
|
Defaults for mutual authentication |
|
|
292 | (1) |
|
Mutual authentication via SSL |
|
|
293 | (1) |
|
Mutual authentication via TrustedHosts |
|
|
293 | (1) |
|
|
|
294 | (1) |
|
|
|
295 | (1) |
|
24 Using regular expressions to parse text files |
|
|
296 | (7) |
|
24.1 The purpose of regular expressions |
|
|
297 | (1) |
|
24.2 A regex syntax primer |
|
|
297 | (2) |
|
24.3 Using regex with -Match |
|
|
299 | (1) |
|
24.4 Using regex with Select-String |
|
|
299 | (2) |
|
|
|
301 | (1) |
|
|
|
301 | (1) |
|
|
|
302 | (1) |
|
25 Additional random tips, tricks, and techniques |
|
|
303 | (13) |
|
25.1 Profiles, prompts, and colors: customizing the shell |
|
|
303 | (4) |
|
|
|
303 | (2) |
|
|
|
305 | (1) |
|
|
|
306 | (1) |
|
25.2 Operators: -as, -is, -replace, join, -split, -in, -contains |
|
|
307 | (3) |
|
|
|
307 | (1) |
|
|
|
308 | (1) |
|
|
|
308 | (1) |
|
|
|
309 | (1) |
|
|
|
310 | (1) |
|
|
|
311 | (1) |
|
25.5 Dealing with WMI dates |
|
|
312 | (1) |
|
25.6 Setting default parameter values |
|
|
313 | (2) |
|
25.7 Playing with script blocks |
|
|
315 | (1) |
|
25.8 More tips, tricks, and techniques |
|
|
315 | (1) |
|
26 Using someone else's script |
|
|
316 | (9) |
|
|
|
317 | (4) |
|
26.2 It's a line-by-line examination |
|
|
321 | (1) |
|
|
|
321 | (2) |
|
|
|
323 | (2) |
|
|
|
325 | (3) |
|
27.1 Ideas for further exploration |
|
|
325 | (1) |
|
27.2 "Now that I've read the book, where do I start?" |
|
|
326 | (1) |
|
27.3 Other resources you'll grow to love |
|
|
327 | (1) |
|
28 PowerShell cheat sheet |
|
|
328 | (7) |
|
|
|
328 | (3) |
|
|
|
331 | (1) |
|
|
|
332 | (1) |
|
28.4 Custom property and column syntax |
|
|
332 | (1) |
|
28.5 Pipeline parameter input |
|
|
333 | (1) |
|
|
|
334 | (1) |
| Appendix Review labs |
|
335 | (12) |
| Index |
|
347 | |