Muutke küpsiste eelistusi

Learn PowerShell Scripting in a Month of Lunches [Pehme köide]

  • Formaat: Paperback / softback, 352 pages, kõrgus x laius x paksus: 235x190x20 mm, kaal: 600 g
  • Ilmumisaeg: 15-Dec-2017
  • Kirjastus: Manning Publications
  • ISBN-10: 1617295094
  • ISBN-13: 9781617295096
Teised raamatud teemal:
  • Formaat: Paperback / softback, 352 pages, kõrgus x laius x paksus: 235x190x20 mm, kaal: 600 g
  • Ilmumisaeg: 15-Dec-2017
  • Kirjastus: Manning Publications
  • ISBN-10: 1617295094
  • ISBN-13: 9781617295096
Teised raamatud teemal:

Summary

Discover how scripting is different from command-line PowerShell, as you explore concrete hands-on examples in this handy guide. The book includes and expands on many of the techniques presented in Learn PowerShell Toolmaking in a Month of Lunches.

Purchase of the print book includes a free eBook in PDF, Kindle, and ePub formats from Manning Publications.

About the Technology

Automate it! With Microsoft's PowerShell language, you can write scripts to control nearly every aspect of Windows. Just master a few straightforward scripting skills, and you'll be able to eliminate repetitive manual tasks, create custom reusable tools, and build effective pipelines and workflows. Once you start scripting in PowerShell, you'll be amazed at how many opportunities you'll find to save time and effort.

About the Book

Learn PowerShell Scripting in a Month of Lunches teaches you how to expand your command-line PowerShell skills into effective scripts and tools. In 27 bite-size lessons, you'll discover instantly useful techniques for writing efficient code, finding and squashing bugs, organizing your scripts into libraries, and much more. Advanced scripters will even learn to access the .NET Framework, store data long term, and create nice user interfaces.

What's Inside

  • Designing functions and scripts
  • Effective pipeline usage
  • Dealing with errors and bugs
  • Professional-grade scripting practices

About the Reader

Written for devs and IT pros comfortable with PowerShell and Windows.

About the Authors

Don Jones is a PowerShell MVP, speaker, and trainer who has written dozens of books on information technology topics. Jeffery Hicks is a PowerShell MVP and an independent consultant, trainer, and author. Don and Jeff coauthored Manning's Learn Windows PowerShell in a Month of Lunches, Learn PowerShell Toolmaking in a Month of Lunches, and PowerShell in Depth.

Table of Contents

    PART 1 - INTRODUCTION TO SCRIPTING

  1. Before you begin
  2. Setting up your scripting environment
  3. WWPD: what would PowerShell do?
  4. Review: parameter binding and the PowerShell pipeline
  5. Scripting language crash course
  6. The many forms of scripting (and which to use)
  7. Scripts and security
  8. PART 2 - BUILDING A POWERSHELL SCRIPT

  9. Always design first
  10. Avoiding bugs: start with a command
  11. Building a basic function and script module
  12. Going advanced with your function
  13. Objects: the best kind of output
  14. Using all the pipelines
  15. Simple help: making a comment
  16. Dealing with errors
  17. Filling out a manifest
  18. PART 3 - GROWN-UP SCRIPTING

  19. Changing your brain when it comes to scripting
  20. Professional-grade scripting
  21. An introduction to source control with git
  22. Pestering your script
  23. Signing your script
  24. Publishing your script
  25. PART 4 - ADVANCED TECHNIQUES

  26. Squashing bugs
  27. Making script output prettier
  28. Wrapping up the .NET Framework
  29. Storing data-not in Excel!
  30. Never the end
Preface xvii
Acknowledgments xix
About This Book xx
About The Authors xxii
Part 1: Introduction To Scripting 1(66)
1 Before you begin
3(5)
1.1 What is toolmaking?
3(1)
1.2 Is this book for you?
4(1)
1.3 Here's what you need to have
5(1)
PowerShell version
5(1)
Administrative privileges
5(1)
SQL Server
5(1)
Script editor
6(1)
1.4 How to use this book
6(1)
1.5 Expectations
7(1)
1.6 How to ask for help
7(1)
1.7 Summary
7(1)
2 Setting up your scripting environment
8(11)
2.1 The operating system
8(1)
2.2 Windows PowerShell
9(1)
2.3 Administrative privileges and execution policy
9(1)
2.4 A script editor
9(4)
2.5 Setting up a virtual environment
13(1)
2.6 Example code
14(1)
2.7 SQL Server Express
14(4)
2.8 Your turn
18(1)
3 WWPD: what would PowerShell do?
19(6)
3.1 Writing single-task tools
19(1)
3.2 Naming tools
20(1)
3.3 Naming parameters
21(1)
3.4 Producing output
22(1)
3.5 Don't assume
23(1)
3.6 Avoid innovation
23(1)
3.7 Summary
24(1)
4 Review: parameter binding and the PowerShell pipeline
25(11)
4.1 Visualizing the pipeline
25(1)
4.2 It's all in the parameters
26(1)
4.3 Plan A: ByValue
27(4)
Introducing Trace-Command
28(1)
Tracing ByValue parameter binding
28(3)
When ByValue fails
31(1)
4.4 ByPropertyName
31(4)
Let's trace ByPropertyName
32(2)
When ByPropertyName fails
34(1)
Planning ahead
35(1)
4.5 Summary
35(1)
5 Scripting language crash course
36(12)
5.1 Comparisons
36(2)
Wildcards
37(1)
Collections
38(1)
Troubleshooting comparisons
38(1)
5.2 The If construct
38(3)
5.3 The ForEach construct
41(3)
5.4 The Switch construct
44(1)
5.5 The Do/While construct
44(1)
5.6 The For construct
45(1)
5.7 Break
46(1)
5.8 Summary
47(1)
6 The many forms of scripting (and which to use)
48(10)
6.1 Tools vs. controllers
48(1)
6.2 Thinking about tools
49(2)
6.3 Thinking about controllers
51(1)
6.4 Comparing tools and controllers
52(1)
6.5 Some concrete examples
52(4)
Emailing users whose passwords are about to expire
53(1)
Provisioning new users
53(1)
Setting file permissions
54(1)
Helping the help desk
55(1)
6.6 Control more
56(1)
6.7 Your turn
56(2)
7 Scripts and security
58(9)
7.1 PowerShell's script security goal
58(1)
7.2 Execution policy
59(4)
Execution scope
61(1)
Getting your policies
62(1)
Setting an execution policy
62(1)
7.3 PowerShell isn't the default application
63(1)
7.4 Running scripts
63(2)
7.5 Recommendations
65(1)
7.6 Summary
66(1)
Part 2: Building A Powershell Script 67(102)
8 Always design first
69(11)
8.1 Tools do one thing
69(2)
8.2 Tools are testable
71(1)
8.3 Tools are flexible
72(1)
8.4 Tools look native
72(1)
8.5 For example
73(4)
8.6 Your turn
77(3)
Start here
77(1)
Your task
78(1)
Our take
78(2)
9 Avoiding bugs: start with a command
80(8)
9.1 What you need to run
80(2)
9.2 Breaking it down, and running it right
82(1)
9.3 Running commands and digging deeper
83(2)
9.4 Process matters
85(1)
9.5 Know what you need
85(1)
9.6 Your turn
85(3)
Start here
86(1)
Your task
86(1)
Our take
86(2)
10 Building a basic function and script module
88(11)
10.1 Starting with a basic function
88(4)
Designing the input parameters
89(1)
Writing the code
90(1)
Designing the output
91(1)
10.2 Creating a script module
92(1)
10.3 Prereq check
93(1)
10.4 Running the command
93(2)
10.5 Your turn
95(4)
Start here
95(1)
Your task
96(1)
Our take
96(3)
11 Going advanced with your function
99(12)
11.1 About CmdletBinding and common parameters
99(8)
Accepting pipeline input
101(3)
Mandatory-ness
104(1)
Parameter validation
104(1)
Parameter aliases
105(1)
Supporting-Confirm and-WhatIf
106(1)
11.2 Your turn
107(4)
Start here
108(1)
Your task
108(1)
Our take
108(3)
12 Objects: the best kind of output
111(11)
12.1 Assembling the information
112(1)
12.2 Constructing and emitting output
113(1)
12.3 A quick test
114(2)
12.4 An object alternative
116(1)
12.5 Enriching objects
117(1)
12.6 Your turn
118(4)
Start here
118(1)
Your task
119(1)
Our take
120(2)
13 Using all the pipelines
122(14)
13.1 Knowing the six channels
122(1)
13.2 Adding verbose and warning output
123(2)
13.3 Doing more with-Verbose
125(2)
13.4 Information output
127(5)
A detailed information example
129(3)
13.5 Your turn
132(4)
Start here
132(2)
Your task
134(1)
Our take
134(2)
14 Simple help: making a comment
136(10)
14.1 Where to put your help
136(1)
14.2 Getting started
137(3)
14.3 Going further with comment-based help
140(1)
14.4 Broken help
140(1)
14.5 Beyond comments
140(1)
14.6 Your turn
141(5)
Start here
141(2)
Your task
143(1)
Our take
143(3)
15 Dealing with errors
146(12)
15.1 Understanding errors and exceptions
146(1)
15.2 Bad handling
147(1)
15.3 Two reasons for exception handling
148(1)
15.4 Handling exceptions in your tool
148(3)
15.5 Capturing the exception
151(1)
15.6 Handling exceptions for non-commands
151(1)
15.7 Going further with exception handling
152(1)
15.8 Your turn
153(5)
Start here
153(1)
Your task
154(1)
Our take
155(3)
16 Filling out a manifest
158(11)
16.1 Module execution order
158(1)
16.2 Creating a new manifest
159(3)
16.3 Examining the manifest
162(2)
Metadata
162(1)
The root module
162(1)
Prerequisites
162(1)
Scripts, types, and formats
163(1)
Exporting members
163(1)
16.4 Your turn
164(7)
Start here
164(1)
Your task
165(1)
Our take
166(3)
Part 3: Grown-Up Scripting 169(84)
17 Changing your brain when it comes to scripting
171(19)
17.1 Example 1
171(4)
The critique
172(1)
Our take
173(2)
Thinking beyond the literal
175(1)
17.2 Example 2
175(13)
The walkthrough
180(2)
Our take
182(6)
17.3 Your turn
188(2)
Start here
188(1)
Your task
189(1)
Our take
189(1)
18 Professional-grade scripting
190(12)
18.1 Using source control
190(1)
18.2 Spelling it out
191(1)
18.3 Commenting your code
192(1)
18.4 Formatting your code
193(3)
18.5 Using meaningful non-Hungarian variable names
196(1)
18.6 Avoiding aliases
196(1)
18.7 Avoiding awkward pipelines
197(1)
18.8 Providing help
197(1)
18.9 Avoiding Write-Host and Read-Host
197(1)
18.10 Sticking with single quotes
198(1)
18.11 Not polluting the global scope
198(1)
18.12 Being flexible
199(1)
18.13 Being secure
199(1)
18.14 Striving for elegance
200(1)
18.15 Summary
201(1)
19 An introduction to source control with git
202(19)
19.1 Why source control?
202(1)
19.2 What is git?
203(1)
Installing git
203(1)
Git basics
204(1)
19.3 Repository basics
204(7)
Creating a repository
205(1)
Staging a change
205(1)
Committing a change
206(1)
Rolling back a change
207(2)
Branching and merging
209(2)
19.4 Using git with VS Code
211(4)
19.5 Integrating with GitHub
215(4)
19.6 Summary
219(2)
20 Pestering your script
221(13)
20.1 The vision
221(1)
20.2 Problems with manual testing
222(1)
20.3 Benefits of automated testing
222(1)
20.4 Introducing Pester
222(1)
20.5 Coding to be tested
223(1)
20.6 What do you test?
223(1)
Integration tests
223(1)
Unit tests
224(1)
Don't test what isn't yours
224(1)
20.7 Writing a basic Pester test
224(8)
Creating a fixture
226(1)
Writing the first test
227(1)
Creating a mock
227(1)
Adding more tests
228(2)
Code coverage
230(2)
20.8 Summary
232(2)
21 Signing your script
234(10)
21.1 Why sign your scripts?
234(1)
21.2 A word about certificates
235(1)
21.3 Setting your policy
236(1)
21.4 Code-signing basics
237(6)
Getting a code-signing certificate
237(2)
Trusting self-signed certificates
239(1)
Signing your scripts
240(2)
Testing script signatures
242(1)
21.5 Summary
243(1)
22 Publishing your script
244(9)
22.1 Why publish?
244(1)
22.2 Meet the PowerShell Gallery
244(1)
22.3 Other publishing targets
245(1)
22.4 Before you publish
245(1)
Are you reinventing the wheel?
245(1)
Updating your manifest
245(1)
Getting an API key
246(1)
22.5 Ready, set, publish
246(2)
Managing revisions
247(1)
22.6 Publishing scripts
248(3)
Using the Microsoft script repository
248(1)
Creating ScriptFileInfo
249(2)
Publishing the script
251(1)
Managing published scripts
251(1)
22.7 Summary
251(2)
Part 4: Advanced Techniques 253(65)
23 Squashing bugs
255(17)
23.1 The three kinds of bugs
255(1)
23.2 Dealing with syntax bugs
256(1)
23.3 Dealing with results bugs
257(1)
23.4 Dealing with logic bugs
258(9)
Setting breakpoints
259(5)
Setting watches
264(1)
So much more
264(2)
Don't be lazy
266(1)
23.5 Your turn
267(5)
Start here
267(2)
Your task
269(1)
Our take
269(3)
24 Making script output prettier
272(20)
24.1 Our starting point
272(1)
24.2 Creating a default view
273(12)
Exploring Microsoft's views
273(3)
Adding a custom type name to output objects
276(1)
Creating a new view file
277(5)
Adding the view file to a module
282(3)
24.3 Your turn
285(7)
Start here
285(1)
Your task
286(1)
Our take
286(6)
25 Wrapping up the .NET Framework
292(10)
25.1 Why does PowerShell exist?
292(1)
25.2 A crash course in .NET
293(1)
25.3 Exploring a class
294(2)
25.4 Making a wrapper
296(3)
25.5 A more practical example
299(1)
25.6 Your turn
300(2)
Start here
300(1)
Your task
300(1)
Our take
300(2)
26 Storing data-not in Excel!
302(12)
26.1 Introducing SQL Server!
302(1)
26.2 Setting up everything
303(2)
26.3 Using your database: creating a table
305(3)
26.4 Saving data to SQL Server
308(3)
26.5 Querying data from SQL Server
311(2)
26.6 Summary
313(1)
27 Never the end
314(4)
27.1 Welcome to toolmaking
314(1)
27.2 Taking your next step
315(1)
27.3 What's in your future?
316(2)
Index 318
Don Jones is a PowerShell MVP, speaker, and trainer who has written dozens of books on information technology topics.

 

Jeffery Hicks is a PowerShell MVP and an independent consultant, trainer, and author.

 

Don and Jeff co-authored Learn Windows PowerShell in a Month of Lunches and PowerShell in Depth.