O'Reilly logo

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Enterprise PowerShell Scripting Bootcamp

Book Description

The quick start guide for an advanced enterprise PowerShell framework

About This Book

  • Introduces industry-proven techniques that improve script efficiency and reliability
  • Example-rich guide based on real-world scenarios
  • Facilitates building a script that can fully scan a Windows server and identify components

Who This Book Is For

This book is for IT professionals and Windows administrators who would like to gain intensive, hands-on knowledge and skills on PowerShell without spending hours and hours in learning. If you have been struggling to find the time to gain proficiency and confidence with PowerShell and everyday scripting tasks

What You Will Learn

  • Create an advanced PowerShell scripting template that provides repeatable code to jumpstart all of your scripting projects
  • Learn how to securely encrypt and store usernames, passwords, and other sensitive data in PowerShell scripts and answer files
  • Understand how to optimize the performance of scripts to help process large datasets quickly and avoid time-consuming mistakes
  • Develop a script to scan for non-standard Windows Server configurations and identify service accounts used on Windows Servers
  • Gather a large list of data from a Windows server without locally or remotely logging in interactively

In Detail

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.

Style and approach

This book is all about fast and intensive learning. This means, we don’t waste time in helping readers get started. The new content is about leveraging highly-effective examples to build new things, help solving problems in newer and unseen ways, and providing an enterprise-ready platform to create PowerShell Scripts.

Downloading the example code for this book. You can download the example code files for all Packt books you have purchased from your account at http://www.PacktPub.com. If you purchased this book elsewhere, you can visit http://www.PacktPub.com/support and register to have the code file.

Table of Contents

  1. Enterprise PowerShell Scripting Bootcamp
    1. Table of Contents
    2. Enterprise PowerShell Scripting Bootcamp
    3. Credits
    4. About the Author
    5. About the Reviewer
    6. www.PacktPub.com
      1. eBooks, discount offers, and more
        1. Why subscribe?
    7. Customer Feedback
    8. Preface
      1. What this book covers
      2. What you need for this book
      3. Who this book is for
      4. Conventions
      5. Reader feedback
      6. Customer support
        1. Downloading the example code
        2. Downloading the color images of this book
        3. Errata
        4. Piracy
        5. Questions
    9. 1. Getting Started with Enterprise PowerShell Scripting
      1. Windows server scanning script
      2. Performance considerations
      3. PowerShell scripting templates
      4. Summary
    10. 2. Script Structure, Comment Blocks, and Script Logging
      1. Overall script structure
      2. Comment blocks
      3. Script logging
        1. Creating the logging files
        2. Creating a windows event log source
        3. Creating the logging function
      4. Summary
    11. 3. Working with Answer Files
      1. Answer files
        1. XML answer files
          1. Reading XML answer files
          2. XML tag function
      2. Summary
    12. 4. String Encryption and Decryption
      1. RijndaelManaged encryption
        1. Creating random salt, initialization vector, and passwords
      2. Encrypting and decrypting strings
        1. Decrypting strings
        2. Securing the password
          1. Decryption with encoded password
      3. Summary
    13. 5. Interacting with Services, Processes, Profiles, and Logged on Users
      1. Windows services
      2. Managing Windows processes
      3. Identifying logged on users
      4. User profiles
      5. Summary
    14. 6. Evaluating Scheduled Tasks
      1. Scheduled tasks
      2. Identifying scheduled tasks running as alternate users
      3. Summary
    15. 7. Determining Disk Statistics
      1. Disk statistics
        1. Retrieving physical and logical disk information
        2. The DriveType property
        3. Converting disk space to MB and GB
        4. Free Space property
      2. Disk information script
      3. Summary
    16. 8. Windows Features and Installed Software Detection
      1. Windows features
      2. Installed software detection
        1. Scanning executables in \Program Files
      3. Summary
    17. 9. File Scanning
      1. File scanning
      2. Excluding long paths
      3. Excluding files
      4. Summary
    18. 10. Optimizing Script Execution Speed
      1. Script execution speed
        1. Speed considerations for the write-host cmdlet
        2. Speed considerations for the write-progress cmdlet
        3. Speed consideration - switches versus if statements
      2. Summary
    19. 11. Improving Performance by Using Regular Expressions
      1. Using regular expressions
      2. Dynamically building expressions
      3. Implementating regular expression performance
      4. Summary
    20. 12. Overall Script Workflow, Termination Files, and Merging Data Results
      1. Windows server scanning script overview
      2. Pre-script security
        1. Script 1 - randomized password and string generator
        2. Script 2 - string encryption script
      3. XML answer file creation
      4. PowerShell script 3 - the termination files
      5. PowerShell script 4 - merging the scanning script result data
      6. Summary
    21. 13. Creating the Windows Server Scanning Script and Post-Execution Cleanup
      1. Windows server scanning script creation
        1. Comment block
        2. Parameter block
        3. Answer file reading function
        4. Decryption function
        5. Populating script answers in variables and arrays
        6. Creating the log files and logging function
      2. Creating a termination function
      3. Multiple Windows server scanning script functions
        1. Scheduled tasks function
        2. Windows processes function
        3. Windows services function
        4. Installed software function
        5. User profiles function
        6. Windows features function
        7. Scan files and folders function
        8. Invoking the functions
      4. Running the script
      5. Performing script cleanup
      6. Summary
    22. Index