Learn Windows PowerShell in a Month of Lunches [3 ed.] 9781617294167, 1617294160

Summary Learn Windows PowerShell in a Month of Lunches, Third Editionis an innovative tutorial designed for busy IT pro

2,144 474 42MB

English Pages 384 [386] Year 2016

Report DMCA / Copyright

DOWNLOAD FILE

Learn Windows PowerShell in a Month of Lunches [3 ed.]
 9781617294167, 1617294160

Table of contents :
Learn Windows PowerShell 3e......Page 1
contents......Page 8
preface......Page 18
acknowledgments......Page 20
about this book......Page 21
Author Online......Page 22
about the authors......Page 23
1.1 Why you can’t afford to ignore PowerShell......Page 24
1.1.2 Life with PowerShell......Page 25
1.3 Is this book for you?......Page 26
1.4.1 The main chapters......Page 27
1.4.6 Above and beyond......Page 28
1.5 Setting up your lab environment......Page 29
1.6 Installing Windows PowerShell......Page 30
1.8 Being immediately effective with PowerShell......Page 31
2.1 Choose your weapon......Page 32
2.1.1 The console window......Page 34
2.1.2 The Integrated Scripting Environment......Page 36
2.2 It’s typing class all over again......Page 38
2.4 What version is this?......Page 40
2.5 Lab......Page 41
3.1 The help system: how you discover commands......Page 43
3.2 Updatable help......Page 45
3.3 Asking for help......Page 46
3.4 Using help to find commands......Page 47
3.5.1 Parameter sets and common parameters......Page 49
3.5.3 Positional parameters......Page 51
3.5.4 Parameter values......Page 53
3.6 Accessing “about” topics......Page 56
3.8 Lab......Page 57
3.9 Lab answers......Page 59
4.1 Not scripting, but running commands......Page 60
4.2 The anatomy of a command......Page 61
4.3 The cmdlet naming convention......Page 62
4.4 Aliases: nicknames for commands......Page 63
4.5.3 Using positional parameters......Page 65
4.7 Support for external commands......Page 67
4.8 Dealing with errors......Page 71
4.9.2 Typing parameters......Page 72
4.10 Lab......Page 73
5.1 What are providers?......Page 74
5.2 Understanding how the filesystem is organized......Page 76
5.4 Navigating the filesystem......Page 78
5.5 Using wildcards and literal paths......Page 80
5.6 Working with other providers......Page 81
5.7 Lab......Page 84
5.9 Lab answers......Page 85
6.1 Connecting one command to another: less work for you......Page 86
6.2 Exporting to a CSV or an XML file......Page 87
6.2.1 Exporting to CSV......Page 88
6.2.2 Exporting to XML......Page 89
6.2.3 Comparing files......Page 90
6.3 Piping to a file or a printer......Page 92
6.4 Converting to HTML......Page 93
6.5 Using cmdlets that modify the system: killing processes and stopping services......Page 94
6.6 Common points of confusion......Page 95
6.7 Lab......Page 97
6.8 Lab answers......Page 98
7.1 How one shell can do everything......Page 99
7.2 About product-specific “management shells”......Page 100
7.3 Extensions: finding and adding snap-ins......Page 101
7.4 Extensions: finding and adding modules......Page 103
7.5 Command conflicts and removing extensions......Page 105
7.7 Playing with a new module......Page 106
7.8 Profile scripts: preloading extensions when the shell starts......Page 108
7.9 Getting modules from the internet......Page 109
7.11 Lab......Page 110
7.12 Lab answers......Page 111
8.1 What are objects?......Page 112
8.2 Understanding why PowerShell uses objects......Page 113
8.3 Discovering objects: Get-Member......Page 115
8.5 Using object actions, or methods......Page 117
8.6 Sorting objects......Page 118
8.7 Selecting the properties you want......Page 119
8.8 Objects until the end......Page 120
8.10 Lab......Page 122
8.11 Lab answers......Page 123
9.2 How PowerShell passes data down the pipeline......Page 124
9.3 Plan A: pipeline input ByValue......Page 125
9.4 Plan B: pipeline input ByPropertyName......Page 129
9.5 When things don’t line up: custom properties......Page 134
9.6 Parenthetical commands......Page 137
9.7 Extracting the value from a single property......Page 138
9.8 Lab......Page 144
9.10 Lab answers......Page 145
10.1 Formatting: making what you see prettier......Page 146
10.2 Working with the default formatting......Page 147
10.3 Formatting tables......Page 150
10.4 Formatting lists......Page 151
10.5 Formatting wide lists......Page 152
10.6 Creating custom columns and list entries......Page 153
10.9.1 Always format right......Page 156
10.9.2 One type of object at a time, please......Page 158
10.11 Further exploration......Page 160
10.12 Lab answers......Page 161
11.1 Making the shell give you just what you need......Page 162
11.3 Using comparison operators......Page 163
11.4 Filtering objects out of the pipeline......Page 165
11.5 Using the iterative command-line model......Page 167
11.6.1 Filter left, please......Page 168
11.7 Lab......Page 169
11.9 Lab answers......Page 170
12.2 Finding the commands......Page 171
12.3 Learning to use the commands......Page 173
12.4 Tips for teaching yourself......Page 174
12.6 Lab answer......Page 175
13 Remote control: one-to-one, and one-to-many......Page 176
13.1 The idea behind remote PowerShell......Page 177
13.2 WinRM overview......Page 178
13.3 Using Enter-PSSession and Exit-PSSession for one-to-one remoting......Page 182
13.4 Using Invoke-Command for one-to-many remoting......Page 184
13.5 Differences between remote and local commands......Page 186
13.5.1 Invoke-Command vs. -computerName......Page 187
13.5.2 Local vs. remote processing......Page 188
13.5.3 Deserialized objects......Page 189
13.6 But wait, there’s more......Page 190
13.8 Common points of confusion......Page 191
13.9 Lab......Page 192
13.11 Lab answers......Page 193
14 Using Windows Management Instrumentation and CIM......Page 194
14.1 WMI essentials......Page 195
14.2 The bad news about WMI......Page 196
14.3 Exploring WMI......Page 197
14.4 Choose your weapon: WMI or CIM......Page 200
14.5 Using Get-WmiObject......Page 201
14.8 Common points of confusion......Page 205
14.9 Lab......Page 206
14.11 Lab answers......Page 207
15.1 Making PowerShell do multiple things at the same time......Page 208
15.2 Synchronous vs. asynchronous......Page 209
15.3 Creating a local job......Page 210
15.4 WMI, as a job......Page 211
15.6 Getting job results......Page 212
15.7 Working with child jobs......Page 215
15.8 Commands for managing jobs......Page 217
15.9 Scheduled jobs......Page 219
15.10 Common points of confusion......Page 220
15.11 Lab......Page 221
15.12 Lab answers......Page 222
16.1 Automation for mass management......Page 223
16.2 The preferred way: “batch” cmdlets......Page 224
16.3 The CIM/WMI way: invoking methods......Page 225
16.4 The backup plan: enumerating objects......Page 229
16.5.1 Which way is the right way?......Page 234
16.5.2 WMI methods vs. cmdlets......Page 235
16.5.4 ForEach-Object confusion......Page 236
16.7 Lab answers......Page 237
17.1 Keeping the shell secure......Page 239
17.2 Windows PowerShell security goals......Page 240
17.3.1 Execution policy settings......Page 241
17.3.2 Digital code signing......Page 245
17.5 Other security holes?......Page 248
17.6 Security recommendations......Page 249
17.7 Lab......Page 250
18.1 Introduction to variables......Page 251
18.2 Storing values in variables......Page 252
18.3 Using variables: fun tricks with quotes......Page 254
18.4 Storing many objects in a variable......Page 256
18.4.1 Working with single objects in a variable......Page 257
18.4.2 Working with multiple objects in a variable......Page 258
18.4.3 Other ways to work with multiple objects......Page 259
18.5 More tricks with double quotes......Page 260
18.6 Declaring a variable’s type......Page 262
18.7 Commands for working with variables......Page 264
18.10 Lab......Page 265
18.12 Lab answers......Page 266
19.1 Prompting for, and displaying, information......Page 267
19.2 Read-Host......Page 268
19.3 Write-Host......Page 271
19.4 Write-Output......Page 272
19.5 Other ways to write......Page 274
19.8 Lab answers......Page 275
20.1 Making PowerShell remoting a bit easier......Page 276
20.2 Creating and using reusable sessions......Page 277
20.3 Using sessions with Enter-PSSession......Page 278
20.4 Using sessions with Invoke-Command......Page 280
20.5 Implicit remoting: importing a session......Page 281
20.6 Using disconnected sessions......Page 283
20.7 Lab......Page 284
20.9 Lab answers......Page 285
21.1 Not programming, more like batch files......Page 286
21.2 Making commands repeatable......Page 287
21.3 Parameterizing commands......Page 288
21.4 Creating a parameterized script......Page 290
21.5 Documenting your script......Page 291
21.6 One script, one pipeline......Page 293
21.7 A quick look at scope......Page 296
21.8 Lab......Page 297
21.9 Lab answer......Page 298
22.1 Starting point......Page 299
22.2 Getting PowerShell to do the hard work......Page 300
22.3 Making parameters mandatory......Page 301
22.4 Adding parameter aliases......Page 303
22.5 Validating parameter input......Page 304
22.6 Adding the warm and fuzzies with verbose output......Page 305
22.8 Lab answer......Page 307
23.1 Using other endpoints......Page 309
23.2 Creating custom endpoints......Page 310
23.2.1 Creating the session configuration......Page 311
23.2.2 Registering the session......Page 312
23.3 Enabling multihop remoting......Page 314
23.4.1 Defaults for mutual authentication......Page 315
23.4.3 Mutual authentication via TrustedHosts......Page 316
23.5 Lab......Page 317
23.6 Lab answer......Page 318
24 Using regular expressions to parse text files......Page 319
24.2 A regex syntax primer......Page 320
24.4 Using regex with Select-String......Page 322
24.6 Further exploration......Page 324
24.7 Lab answers......Page 325
25.1.1 PowerShell profiles......Page 326
25.1.2 Customizing the prompt......Page 328
25.1.3 Tweaking colors......Page 329
25.2.1 -as and -is......Page 330
25.2.3 -join and -split......Page 331
25.2.4 -contains and -in......Page 332
25.3 String manipulation......Page 333
25.4 Date manipulation......Page 334
25.5 Dealing with WMI dates......Page 335
25.6 Setting default parameter values......Page 336
25.8 More tips, tricks, and techniques......Page 338
26 Using someone else’s script......Page 339
26.1 The script......Page 340
26.3 Lab......Page 344
26.4 Lab answer......Page 346
27.1 Ideas for further exploration......Page 348
27.2 “Now that I’ve read the book, where do I start?”......Page 349
27.3 Other resources you’ll grow to love......Page 350
28.1 Punctuation......Page 351
28.2 Help file......Page 354
28.4 Custom property and column syntax......Page 355
28.5 Pipeline parameter input......Page 356
28.6 When to use $_......Page 357
Review lab 1: chapters 1–6......Page 358
Review lab 2: chapters 1–14......Page 361
Review lab 3: chapters 1–19......Page 363
Answers......Page 364
A......Page 370
C......Page 371
D......Page 372
F......Page 373
H......Page 374
K......Page 375
N......Page 376
P......Page 377
R......Page 379
S......Page 380
T......Page 381
W......Page 382
X......Page 383

Polecaj historie