PowerShell for Sysadmins: Workflow Automation Made Easy

This document was uploaded by one of our users. The uploader already confirmed that they had the permission to publish it. If you are author/publisher or own the copyright of this documents, please report to us by using this DMCA report form.

Simply click on the Download Book button.

Yes, Book downloads on Ebookily are 100% Free.

Sometimes the book is free on Amazon As well, so go ahead and hit "Search on Amazon"

Learn to use PowerShell, Microsoft's scripting language, to automate real-world tasks that IT professionals and system administrators deal with every day. Save Time. Automate. PowerShell® is both a scripting language and an administrative shell that lets you control and automate nearly every aspect of IT. In PowerShell for Sysadmins, five-time Microsoft® MVP "Adam the Automator" Bertram shows you how to use PowerShell to manage and automate your desktop and server environments so that you can head out for an early lunch. You'll learn how to:     Combine commands, control flow, handle errors, write scripts, run scripts remotely, and test scripts with the PowerShell testing framework, Pester     Parse structured data like XML and JSON, work with common domains (like Active Directory, Azure, and Amazon Web Services), and create a real-world server inventory script     Design and build a PowerShell module to demonstrate PowerShell isn't just about ad-hoc scripts     Use PowerShell to create a hands-off, completely automated Windows deployment     Build an entire Active Directory forest from nothing but a Hyper-V host and a few ISO files     Create endless Web and SQL servers with just a few lines of code! Real-world examples throughout help bridge the gap between theory and actual system, and the author's anecdotes keep things lively. Stop with the expensive software and fancy consultants. Learn how to manage your own environment with PowerShell for Sysadmins and make everyone happy. Covers Windows PowerShell v5.1

Author(s): Adam Bertram
Edition: 1
Publisher: No Starch Press
Year: 2020

Language: English
Commentary: Vector PDF
Pages: 320
City: San Francisco, CA
Tags: Amazon Web Services; Microsoft Azure; Programming; Web Applications; PowerShell; System Administration; Pipelines; JSON; Excel; CSV; Microsoft Windows; Refactoring; Object-Oriented Programming; Modules; Microsoft SQL Server; Web Servers; Error Handling; Automation; Testing; Amazon Virtual Private Cloud; Scripts

Brief Contents
Content in Detail
Acknowledgments
Introduction
Why PowerShell?
Who This Book Is For
About This Book
Part I: Fundamentals
Chapter 1: Getting Started
Opening the PowerShell Console
Using DOS Commands
Exploring PowerShell Commands
Getting Help
Displaying the Docs
Learning About General Topics
Updating the Docs
Summary
Chapter 2: Basic PowerShell Concepts
Variables
Displaying and Changing a Variable
User-Defined Variables
Automatic Variables
Data Types
Boolean Values
Integers and Floating Points
Strings
Objects
Inspecting Properties
Using the Get-Member cmdlet
Calling Methods
Data Structures
Arrays
ArrayLists
Hashtables
Creating Custom Objects
Summary
Chapter 3: Combining Commands
Starting a Windows Service
Using the Pipeline
Piping Objects Between Commands
Piping Arrays Between Commands
Looking at Parameter Binding
Writing Scripts
Setting the Execution Policy
Scripting in PowerShell
Summary
Chapter 4: Control Flow
Understanding Control Flow
Using Conditional Statements
Building Expressions by Using Operators
The if Statement
The else Statement
The elseif Statement
The switch Statement
Using Loops
The foreach Loop
The for Loop
The while Loop
The do/while and do/until Loops
Summary
Chapter 5: Error Handling
Working with Exceptions and Errors
Handling Nonterminating Errors
Handling Terminating Errors
Exploring the $Error Automatic Variable
Summary
Chapter 6: Writing Functions
Functions vs. Cmdlets
Defining a Function
Adding Parameters to Functions
Creating a Simple Parameter
The Mandatory Parameter Attribute
Default Parameter Values
Adding Parameter Validation Attributes
Accepting Pipeline Input
Adding Another Parameter
Making the Function Pipeline Compatible
Adding a process Block
Summary
Chapter 7: Exploring Modules
Exploring Default Modules
Finding Modules in Your Session
Finding Modules on Your Computer
Importing Modules
The Components of a PowerShell Module
The .psm1 File
The Module Manifest
Working with Custom Modules
Finding Modules
Installing Modules
Uninstalling Modules
Creating Your Own Module
Summary
Chapter 8: Running Scripts Remotely
Working with Scriptblocks
Using Invoke-Command to Execute Code on Remote Systems
Running Local Scripts on Remote Computers
Using Local Variables Remotely
Working with Sessions
Creating a New Session
Invoking Commands in a Session
Opening Interactive Sessions
Disconnecting from and Reconnecting to Sessions
Removing Sessions with Remove-PSSession
Understanding PowerShell Remoting Authentication
The Double Hop Problem
Double Hopping with CredSSP
Summary
Chapter 9: Testing with Pester
Introducing Pester
Pester Basics
A Pester File
The describe Block
The context Block
The it Block
Assertions
Executing a Pester Test
Summary
Part II: Automating Day-to-Day Tasks
Chapter 10: Parsing Structured Data
CSV Files
Reading CSV Files
Creating CSV Files
Project 1: Building a Computer Inventory Report
Excel Spreadsheets
Creating Excel Spreadsheets
Reading Excel Spreadsheets
Adding to Excel Spreadsheets
Project 2: Creating a Windows Service Monitoring Tool
JSON Data
Reading JSON
Creating JSON Strings
Project 3: Querying and Parsing a REST API
Summary
Chapter 11: Automating Active Directory
Prerequisites
Installing the ActiveDirectory PowerShell Module
Querying and Filtering AD Objects
Filtering Objects
Returning Single Objects
Project 4: Finding User Accounts That Haven’t Changed Their Password in 30 Days
Creating and Changing AD Objects
Users and Computers
Groups
Project 5: Creating an Employee Provisioning Script
Syncing from Other Data Sources
Project 6: Creating a Syncing Script
Mapping Data Source Attributes
Creating Functions to Return Similar Properties
Finding Matches in Active Directory
Changing Active Directory Attributes
Summary
Chapter 12: Working with Azure
Prerequisites
Azure Authentication
Creating a Service Principal
Noninteractively Authenticating with Connect-AzAccount
Creating an Azure Virtual Machine and All Dependencies
Creating a Resource Group
Creating the Network Stack
Creating a Storage Account
Creating the Operating System Image
Wrapping Up
Automating the VM Creation
Deploying an Azure Web App
Creating an App Service Plan and Web App
Deploying an Azure SQL Database
Creating an Azure SQL Server
Creating the Azure SQL Database
Creating the SQL Server Firewall Rule
Testing Your SQL Database
Summary
Chapter 13: Working with AWS
Prerequisites
AWS Authentication
Authenticating with the Root User
Creating an IAM User and Role
Authenticating Your IAM User
Creating an AWS EC2 Instance
The Virtual Private Cloud
The Internet Gateway
Routes
Subnet
Assigning an AMI to Your EC2 Instance
Wrapping Up
Deploying an Elastic Beanstalk Application
Creating the Application
Deploying a Package
Creating a SQL Server Database in AWS
Summary
Chapter 14: Creating a Server Inventory Script
Prerequisites
Creating the Project Script(s)
Defining the Final Output
Discovery and Script Input
Querying Each Server
Thinking Ahead: Combining Different Types of Information
Querying Remote Files
Querying Windows Management Instrumentation
Disk Free Space
Operating System Information
Memory
Network Information
Windows Services
Script Cleanup and Optimization
Summary
Part III: Building Your Own Module
Chapter 15: Provisioning a Virtual Environment
PowerLab Module Prerequisites
Creating the Module
Creating a Blank Module
Creating a Module Manifest
Using Built-In Prefixes for Function Names
Importing the New Module
Automating Virtual Environment Provisioning
Virtual Switches
Creating Virtual Machines
Virtual Hard Disks
Testing the New Functions with Pester
Summary
Chapter 16: Installing an Operating System
Prerequisites
OS Deployments
Creating the VHDX
Attaching the VM
Automating OS Deployments
Storing Encrypted Credentials on Disk
PowerShell Direct
Pester Tests
Summary
Chapter 17: Deploying Active Directory
Prerequisites
Creating an Active Directory Forest
Building the Forest
Saving Secure Strings to Disk
Automating Forest Creation
Populating the Domain
Building and Running Pester Tests
Summary
Chapter 18: Creating and Configuring a SQL Server
Prerequisites
Creating the Virtual Machine
Installing the Operating System
Adding a Windows Unattended Answer File
Adding the SQL Server to a Domain
Installing the SQL Server
Copying Files to the SQL Server
Running the SQL Server Installer
Automating the SQL Server
Running Pester Tests
Summary
Chapter 19: Refactoring Your Code
A Second Look at New-PowerLabSqlServer
Using Parameter Sets
Summary
Chapter 20: Creating and Configuring an IIS Web Server
Prerequisites
Installation and Setup
Building Web Servers from Scratch
The WebAdministration Module
Websites and Application Pools
Configuring SSL on a Website
Summary
Index