Book Image

Windows Server Automation with PowerShell Cookbook - Fourth Edition

By : Thomas Lee
Book Image

Windows Server Automation with PowerShell Cookbook - Fourth Edition

By: Thomas Lee

Overview of this book

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 in an enterprise setting. All scripts are compatible with both Window Server 2022 and 2019. 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.
Table of Contents (18 chapters)
16
Other Books You May Enjoy
17
Index

What this book covers

Chapter 1, Installing and Configuring PowerShell 7, shows you how you can install and configure both PowerShell 7 and VS Code, which replaces the Windows PowerShell Integrated Scripting Environment (ISE), as well as how to install a new font, Cascadia Code. This chapter also examines the PowerShell 7 environment, including the PSReadLine module.

Chapter 2, Introducing PowerShell 7, looks at what's new in PowerShell 7. This chapter examines the new features you can use with PowerShell 7, including a number of new operators and improvements in parallel processing. The chapter also looks at how PowerShell 7 formats and manages error messages.

Chapter 3, Exploring Compatibility with Windows PowerShell, explores PowerShell 7's compatibility with Windows PowerShell. PowerShell 7 is based on the open-source .NET, which is largely, but not fully, compatible with the older .NET Framework. This means some features of Windows PowerShell do not work natively within PowerShell 7, including many of the Windows PowerShell modules that come with Windows Server. The chapter examines the compatibility mechanism adopted by the PowerShell developers to enable older Windows PowerShell modules to function within PowerShell 7 and to close the gap between what you can do with Windows PowerShell and what you can do with PowerShell 7.

Chapter 4, Using PowerShell 7 in the Enterprise, looks at how you can use various PowerShell 7 features that might be more common within larger enterprises. These include the Remote Server Administration Tools (RSAT), package management and the PowerShell Gallery, and creating a local module repository. The chapter also looks at PowerShell script signing, using shortcuts, and working with archive (.zip) files.

Chapter 5, Exploring .NET, examines .NET, which provides the foundation for PowerShell 7. The chapter looks at .NET assemblies, classes, and methods, and concludes by demonstrating how you can create simple C#-based PowerShell extensions and full cmdlets.

Chapter 6, Managing Active Directory, examines how to install, manage, and leverage Active Directory, including installing domains and child domains, managing AD objects, and leveraging Group Policy. The chapter also examines how you can use PowerShell to report on your AD environment.

Chapter 7, Managing Networking in the Enterprise, shows you how to manage Windows networking with PowerShell. Networks are today central to almost every organization and this chapter looks at a variety of network-related tasks, including looking at new ways to do old things with PowerShell, setting up DNS, DHCP, and DHCP failover and load balancing.

Chapter 8, Implementing Enterprise Security, looks at security aspects within the context of an enterprise environment. The chapter looks at Just Enough Administration (JEA), which limits the actions an administrator can perform remotely. It also looks at the event log, PowerShell 7's script block logging, setting PowerShell 7-related group policies, and configuring a fine-grained AD password policy. The chapter concludes by looking at the Windows Defender Antivirus product built into Windows Server.

Chapter 9, Managing Storage, looks at managing storage in Windows Server, including locally attached devices and Windows Storage Spaces. The chapter also looks at managing Storage Replica, a feature of Windows Server 2022.

Chapter 10, Managing Shared Data, examines different ways to share data and manage your shared data with Windows Server and PowerShell. This includes managing NTFS permissions, creating and securing SMB shares, and setting up and using iSCSI. The chapter concludes by looking at File Server Resource Manager (FSRM), a feature of Windows Server, and managing FSRM quotas, file screening, and reporting.

Chapter 11, Managing Printing, shows you how to manage printers, printer queues, and printer drivers as well as how to set up a printer pool. You also examine how to print a test page.

Chapter 12, Managing Hyper-V, demonstrates the use of Hyper-V. This chapter shows you how to build and deploy VMs with Hyper-V. This includes nested Hyper-V, and running a Hyper-V VM inside another Hyper-V VM, which is useful for a number of scenarios.

Chapter 13, Managing Azure, looks at managing IaaS and PaaS resources in Azure using PowerShell. To test the recipes in this chapter, you need access to Azure. This chapter describes Azure Storage and how to set up a Virtual Machine, an Azure website, and an SMB3 file share.

Chapter 14, Troubleshooting with PowerShell, looks at a number of aspects of both reactive and proactive troubleshooting. This includes using the PowerShell script debugger, getting events from the event log, and using the Best Practices Analyzer contained in Windows Server.

Chapter 15, Managing with Windows Management Instrumentation, examines Windows Management Instrumentation (WMI) and enables you to investigate WMI namespaces, classes, and class occurrences. You retrieve information from WMI classes, update WMI using WMI methods, and manage WMI events including WMI permanent eventing.