Book Image

Enterprise PowerShell Scripting Bootcamp

By : Brenton J.W. Blawat
Book Image

Enterprise PowerShell Scripting Bootcamp

By: Brenton J.W. Blawat

Overview of this book

Enterprise PowerShell Scripting Bootcamp explains how to create your own repeatable PowerShell scripting framework. This framework contains script logging methodologies, answer file interactions, and string encryption and decryption strategies. This book focuses on evaluating individual components to identify the system’s function, role, and unique characteristics. To do this, you will leverage built-in CMDlets and Windows Management Instrumentation (WMI) to explore Windows services, Windows processes, Windows features, scheduled tasks, and disk statistics. You will also create custom functions to perform a deep search for specific strings in files and evaluate installed software through executable properties. We will then discuss different scripting techniques to improve the efficiency of scripts. By leveraging several small changes to your code, you can increase the execution performance by over 130%. By the end of this book, you will be able to tie all of the concepts together in a PowerShell-based Windows server scanning script. This discovery script will be able to scan a Windows server to identify a multitude of components.
Table of Contents (21 chapters)
Enterprise PowerShell Scripting Bootcamp
Credits
About the Author
About the Reviewer
www.PacktPub.com
Customer Feedback
Preface
3
Working with Answer Files
Index

PowerShell scripting templates


As you develop different scripts for your enterprise environment, you will have a core set of functions that you tend to use in all of your scripts. Some enterprise scripters create their own functions, while others leverage scripts from the vast community of PowerShell developers. With either method, you will need a solid foundation to build your scripts on.

Some of the most common items this book provides for scripting templates include:

  • Encryption and decryption technologies: Probably the most common requirement in enterprise environments is security. It's no secret that you should not have clear text administrative-level credentials in scripts. Providing an encryption and decryption function in your scripts is essential to maintaining a secure enterprise.

  • Logging mechanisms: The second most common requirement in enterprise environments is logging script actions. Since scripts are typically executed on a large number of systems at the same time, you will need the ability to track exactly what is being performed on these systems. Creating a logging function will provide the ability to log script actions to both the event log and a log file.

  • Answer file logic: One of the more advanced methods for PowerShell scripting is leveraging an answer file for script variables. The core to the answer file is that you can add, remove, and modify the values in the answer file without having to modify your script. This provides the ability to have flexibility in your scripts without needing to touch any lines of code.

  • Standardized comment blocks: When you are creating scripts, it's essential to give yourself and others reminders of what the script's function is. Comment blocks enable the ability to provide details about the script, revision history, and execution parameters of the script.

Whether you are new to PowerShell scripting or you have been scripting for a long time, this book provides thought-inspiring methods to improve your scripting abilities. As you work through this book, it's strongly encouraged to incorporate these examples in your own scripts. This applied learning methodology will significantly help in your retention of the content, and provide a very robust enterprise scripting platform.