ISBN-13: 9781484263877 / Angielski / Miękka / 2020 / 146 str.
ISBN-13: 9781484263877 / Angielski / Miękka / 2020 / 146 str.
Beginning
Introduction
Chapter 1. Do The Basics
Plan Before you Code
Don’t Reinvent the Wheel
Build Functions as Building Blocks
Build Re-usable Tools
Don’t Focus Purely on Performance
Build Pester tests
Implement Error handling
Build Manageable Code
Don’t Skimp on Security
Log Script Activity
Parameterize Everything
Limit Script and Function Input
Maintain Coding Standards
Code in Context
Return Informative Output
Understand Your Code
Use Version Control
Write for Cross Platform
Write for the Next Person
Use a Code Editor
Chapter 2. Don’t Reinvent the Wheel
Use Community Modules
Leverage Others’ work
Chapter 3: Use Visual Studio Code
PowerShell Integrated Scripting Environment
Using Visual studio over PowerShell ISE
Chapter 4. Plan Before you Code
Write Comments Before Coding
Use your Code as a Todo List
Chapter 5. Create Building Blocks with Functions
Write Functions with One, Single Goal
Build Functions with Pipeline Support
Save Commonly-Used, Interactive Functions to Your Profile
Chapter 6. Parameterize Everything
Don’t Hardcode. Always Use ParametersUse Parameter Sets When All Parameters Should Not be Used at Once
Use a PSCredential Object Rather than a Separate Username and Password
Chapter 7. Log Script Activity
Use a Logging Function
Clean up Verbose Messages
Chapter 8. Build with Manageability in Mind
DRY: Don’t Repeat Yourself
Don’t Store Configuration Items in Code
Always Remove Dead Code
Chapter 9. Be Specific
Use Strict Mode
Don’t Ignore Errors
Validate Input Parameters
Explicitly Define Parameter Types
Enforce Mandatory Parameters
Use the #requires Statement .
Chapter 10. Write for the Next Person
Give your Variables Meaningful Names
String Substitution
Don’t use Aliases in a Script
Put functions in Alphabetical Order in a Module
Explain Regular Expressions with Comments
Write Comment-Based Help
Weigh the Difference Between Performance and Readability
Chapter 11. Handle Errors Gracefully
Force Hard-Terminating Errors
Avoid Using $?
Copy $Error[0] to your Own Variable
Chapter 12. Don’t Skimp on Security
Sign Scripts
Use Scriptblock Logging
Never Store Sensitive Information in Clear Text in CodeDon’t use Invoke-Expression
Use PowerShell Constrained Language Mode
Chapter 13. Stick to PowerShell
Use Native PowerShell Where Possible
Use PowerShell standard cmdlet naming
Chapter 14. Build Tools
Code for Portablity
Wrap Command-Line Utilities in Functions .
Force Functions to Return Common Object Types
Ensure Module Functions Cover all the Verbs
Chapter 15. Return Standardized, Informative Output
Use Progress Bars Wisely
Leave the Format Cmdlets to the Console
Use Write-Verbose
Use Write-Information
Ensure a Command Returns One Type of Object
Only Return Necessary Information to the Pipeline
Chapter 16. Build Scripts for Speed
Use an ArrayList or GenericList .NET Class when Elements Need to be Added to an Array
Use a Regular Expression to Search Multiple String Values
Don’t use Write-Host in Bulk
Don’t use the Pipeline
Use the .foreach() and .where() Methods .
Use Parallel Processing .
Use the .NET StreamReader Class When Reading Large Text Files
Chapter 17: Use Version Control
Create repositories based on a purpose
Commit Code changes based on small goals
Create a branch based on the future
Chapter 18. Build Tests
Learn the Pester Basics
Leverage Infrastructure Tests
Automate Pester Tests
Use PSScriptAnalyzer
Chapter 19. Miscellaneous Tips
Write for Cross Platform .
Don’t Query the Win32_Product CIM Class
Create a Shortcut to run PowerShell as Administrator . .
Store ‘Formatable’ Strings for Use Later
Use Out-GridView for GUI-based Sorting and Filtering
Don’t Make Automation Scripts Interactive
Chapter 20. Summary
Adam Bertram is a 20+ year veteran of IT and an experienced online business professional. He’s a consultant, Microsoft MVP, blogger, trainer, published author and content marketer for multiple technology companies.
Learn to write better PowerShell code via short, example-driven tips. This book covers tips to make your PowerShell scripts faster and easier to read all while following proven best practices. Written by a six-time Microsoft MVP and one of the first Microsoft PowerShell MVPs with over a decade of PowerShell experience, Building Better PowerShell Code gives you easily digestible tips you can begin using immediately. The book starts with an overview of some of the most important tips the author can muster which segues into a deeper dive with dozens of examples throughout the book. It takes you through tips such as using community modules, writing better comments, thinking of PowerShell functions as building blocks, and more. You will also see how to use parameters the right way and how to create simple logging code to easily record script activity.
You will learn not only how to write better code, but also how to implement some mindset tricks, such as being explicit and specific with code and how to write code that reads well. You’ll get into error handling and also how to make your scripts more secure. Finally, you’ll examine the concept of building PowerShell tools and how to build scripts for speed. Other tips and best practices include:After reading this book and applying these tips, you will have an expert coding mindset and be able to build PowerShell code that’s efficient, readable, and compliant with many best practices.
1997-2024 DolnySlask.com Agencja Internetowa