Windows Server Automation with PowerShell Cookbook - Fourth Edition

Book description

Over 100 PowerShell recipes for working more effectively with Windows Server 2022/2019

Key Features

  • Develop a holistic understanding of Windows Server 2022/2019 with PowerShell 7.1
  • Learn best practices for PowerShell scripting to automate common tasks and manage AD, enterprise security, WMI, Azure, and .NET 5
  • Discover new ways to optimize your PowerShell code by working through easy-to-follow recipes

Book Description

With a foreword from PowerShell creator Jeffrey Snover, this heavily updated edition is designed to help you learn how to use PowerShell 7.1 effectively and manage the core roles, features, and services of Windows Server 2022/2019 in an enterprise setting. Brand new to this edition are recipes exploring the .NET Framework, enterprise server security, and managing Windows Server with Windows Management Instrumentation (WMI).

This latest edition equips you with over 100 recipes you'll need in day-to-day work, covering a wide range of fundamental and more advanced use cases. We look at how to install and configure PowerShell 7.1, along with useful new features and optimizations, and how the PowerShell compatibility solution bridges the gap to older versions of PowerShell. Topics include using PowerShell to manage networking and DHCP in Windows Server, objects in Active Directory, Hyper-V, and Azure. Debugging is crucial, so the book shows you how to use some powerful tools to diagnose and resolve issues with Windows Server.

What you will learn

  • Perform key admin tasks on Windows Server 2022/2019
  • Keep your organization secure with JEA, group policies, logs, and Windows Defender
  • Use the .NET Framework for administrative scripting
  • Manage data and storage on Windows, including disks, volumes, and filesystems
  • Create and configure Hyper-V VMs, implementing storage replication and checkpoints
  • Set up virtual machines, websites, and shared files on Azure
  • Report system performance using built-in cmdlets and WMI to obtain single measurements
  • Apply the right tools and modules to troubleshoot and debug Windows Server

Who this book is for

This book is for systems administrators, software architects, developers, or engineers working with Windows Server 2022/2019 seeking to automate tasks more effectively with PowerShell 7.1. Basic knowledge of PowerShell is expected.

Publisher resources

Download Example Code

Table of contents

  1. Preface
    1. Who this book is for
    2. What this book covers
    3. To get the most out of this book
    4. Get in touch
  2. Installing and Configuring PowerShell 7
    1. Introduction
    2. Installing PowerShell 7
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    3. Using the PowerShell 7 console
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    4. Exploring PowerShell 7 installation artifacts
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    5. Building PowerShell 7 profile files
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    6. Installing VS Code
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    7. Installing the Cascadia Code font
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    8. Exploring PSReadLine
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
  3. Introducing PowerShell 7
    1. Introduction
    2. Exploring new operators
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    3. Exploring parallel processing with ForEach-Object
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    4. Improvements in ForEach and ForEach-Object
      1. Getting ready
      2. How to do it...
      3. How it works…
      4. There's more...
    5. Improvements in Test-Connection
      1. Getting ready
      2. How to do it...
      3. How it works…
      4. There's more...
    6. Using Select-String
      1. Getting ready
      2. How to do it...
      3. How it works…
      4. There's more...
    7. Exploring the error view and Get-Error
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    8. Exploring experimental features
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
  4. Exploring Compatibility with Windows PowerShell
    1. Introduction
      1. Module compatibility
      2. Incompatible modules
    2. Exploring compatibility with Windows PowerShell
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    3. Using the Windows PowerShell compatibility solution
      1. Getting ready
      2. How to do it…
      3. How it works...
      4. There's more...
    4. Exploring compatibility solution limitations
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    5. Exploring the module deny list
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    6. Importing format XML
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    7. Leveraging compatibility
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
  5. Using PowerShell 7 in the Enterprise
    1. Introduction
    2. Installing RSAT tools on Windows Server
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    3. Exploring package management
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    4. Exploring PowerShellGet and the PS Gallery
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    5. Creating a local PowerShell repository
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    6. Establishing a script signing environment
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    7. Working with shortcuts and the PSShortcut module
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    8. Working with archive files
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
  6. Exploring .NET
    1. Introduction
    2. Exploring .NET assemblies
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    3. Examining .NET classes
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    4. Leveraging .NET methods
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    5. Creating a C# extension
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    6. Creating a PowerShell cmdlet
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
  7. Managing Active Directory
    1. Introduction
      1. Systems used in this chapter
    2. Installing an AD forest root domain
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    3. Testing an AD installation
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more…
    4. Installing a replica domain controller
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    5. Installing a child domain
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    6. Creating and managing AD users and groups
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    7. Managing AD computers
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    8. Adding users to AD using a CSV file
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    9. Creating Group Policy objects
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    10. Reporting on AD replication
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    11. Reporting on AD computers
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    12. Reporting on AD users
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
  8. Managing Networking in the Enterprise
    1. Introduction
    2. Configuring IP addressing
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    3. Testing network connectivity
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    4. Installing DHCP
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    5. Configuring DHCP scopes and options
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    6. Using DHCP
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    7. Implementing DHCP failover and load balancing
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    8. Deploying DNS in the Enterprise
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    9. Configuring DNS forwarding
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    10. Managing DNS zones and resource records
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
  9. Implementing Enterprise Security
    1. Introduction
    2. Implementing Just Enough Administration (JEA)
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    3. Examining Applications and Services Logs
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    4. Discovering logon events in the event log
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    5. Deploying PowerShell group policies
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    6. Using PowerShell Script Block Logging
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    7. Configuring AD password policies
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    8. Managing Windows Defender Antivirus
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
  10. Managing Storage
    1. Introduction
    2. Managing physical disks and volumes
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    3. Managing filesystems
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    4. Exploring providers and the FileSystem provider
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    5. Managing Storage Replica
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    6. Deploying Storage Spaces
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
  11. Managing Shared Data
    1. Introduction
    2. Managing NTFS file and folder permissions
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    3. Setting up and securing an SMB file server
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. There's more...
    4. Creating and securing SMB shares
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    5. Accessing SMB shares
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    6. Creating an iSCSI target
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    7. Using an iSCSI target
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    8. Implementing FSRM quotas
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    9. Implementing FSRM reporting
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    10. Implementing FSRM file screening
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
  12. Managing Printing
    1. Introduction
    2. Installing and sharing printers
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    3. Publishing a printer
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    4. Changing the spooler directory
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    5. Changing printer drivers
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more…
    6. Printing a test page
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    7. Managing printer security
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    8. Creating a printer pool
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
  13. Managing Hyper-V
    1. Introduction
    2. Installing Hyper-V inside Windows Server
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    3. Creating a Hyper-V VM
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    4. Using PowerShell Direct
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    5. Using Hyper-V VM groups
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    6. Configuring VM hardware
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    7. Configuring VM networking
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    8. Implementing nested virtualization
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    9. Managing VM state
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    10. Managing VM and storage movement
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    11. Managing VM replication
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    12. Managing VM checkpoints
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
  14. Managing Azure
    1. Introduction
    2. Getting started using Azure with PowerShell
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    3. Creating Azure resources
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    4. Exploring the Azure storage account
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    5. Creating an Azure SMB file share
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    6. Creating an Azure website
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    7. Creating an Azure Virtual Machine
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
  15. Troubleshooting with PowerShell
    1. Introduction
    2. Using PowerShell Script Analyzer
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    3. Using Best Practices Analyzer
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    4. Network troubleshooting
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    5. Checking network connectivity using Get-NetView
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    6. Exploring PowerShell script debugging
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
  16. Managing with Windows Management Instrumentation
    1. Introduction
      1. WMI architecture
    2. Exploring WMI in Windows
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    3. Exploring WMI namespaces
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    4. Exploring WMI classes
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    5. Obtaining local and remote WMI objects
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    6. Using WMI methods
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    7. Managing WMI events
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    8. Implementing permanent WMI eventing
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
  17. Other Books You May Enjoy
  18. Index

Product information

  • Title: Windows Server Automation with PowerShell Cookbook - Fourth Edition
  • Author(s): Thomas Lee, Jeffrey Snover
  • Release date: July 2021
  • Publisher(s): Packt Publishing
  • ISBN: 9781800568457