Windows Server Automation with PowerShell Cookbook
eBook - ePub

Windows Server Automation with PowerShell Cookbook

Powerful ways to automate and manage Windows administrative tasks, 4th Edition

  1. 674 pages
  2. English
  3. ePUB (mobile friendly)
  4. Available on iOS & Android
eBook - ePub

Windows Server Automation with PowerShell Cookbook

Powerful ways to automate and manage Windows administrative tasks, 4th Edition

About this book

Develop a holistic understanding of Windows Server with over 100 PowerShell recipes

Key Features

  • Updated with new recipes on the.NET Framework, enterprise server security, and managing Windows Server with WMI
  • Learn PowerShell best practices to automate common tasks and manage AD, enterprise security, 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 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.

What you will learn

  • Perform key admin tasks on Windows Server
  • 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 seeking to automate tasks more effectively with PowerShell 7.1. Basic knowledge of PowerShell is expected.

Trusted by 375,005 students

Access to over 1.5 million titles for a fair monthly price.

Study more efficiently using our study tools.

Information

Year
2021
Edition
4
eBook ISBN
9781800569690

12

Managing Hyper-V

In this chapter, we cover the following recipes:
  • Installing Hyper-V inside Windows Server
  • Creating a Hyper-V VM
  • Using PowerShell Direct
  • Using Hyper-V VM groups
  • Configuring VM hardware
  • Configuring VM networking
  • Implementing nested virtualization
  • Managing VM state
  • Managing VM and storage movement
  • Managing VM replication
  • Managing VM checkpoints

Introduction

Hyper-V is Microsoft's virtual machine (VM) hypervisor. Both Windows Server 2022 and Windows 10 include Hyper-V as an option you can install, on all versions of Windows Server 2022, and the Enterprise, Professional, and Education editions of Windows 10.
Microsoft first released Hyper-V with Server 2008 and has improved it significantly with each successive version of Windows Server. Improvements include additional features, support for the latest hardware, and significantly increased scalability.
Hyper-V supports nested virtualization, the ability to run Hyper-V inside a Hyper-V VM. Nested virtualization has some good use cases, such as in training – for instance, giving each student a VM on a large blade containing the VMs needed for the course labs. Nested virtualization provides an additional layer of security that might be useful in multi-tenant scenarios.
Microsoft also ships a free version of Hyper-V, the Microsoft Hyper-V Server. The Hyper-V Server runs VMs with no GUI. You configure and manage remotely using recipes like the ones in this chapter.
This chapter focuses solely on Hyper-V inside Windows Server 2022, although you can manage Hyper-V Server using the tools used in this chapter's recipes. References to your Hyper-V servers refer to your Windows 2022 servers that have the Hyper-V feature added. Hyper-V's management tools enable you to configure and manage both the Hyper-V service and the VMs running on your Hyper-V servers.
This chapter starts with installing and configuring the Hyper-V feature. After installing Hyper-V, you go on to create a VM, PSDirect, which requires you to download an ISO image of Windows Server from the internet.
After you create the PSDirect VM, you use the VM. You use PowerShell Direct to use a remoting session into the VM without using a network connection. You also configure the VM's hardware and networking capability. You then use PowerShell cmdlets to manage the state of the VM.
Hyper-V allows you to move a VM and/or a VM's storage between Hyper-V hosts. For disaster recovery, you can replicate a running VM (and use that replica should the primary VM fail).
You can take snapshots, or checkpoints, of a VM to save a VM's state and restore your VM to that point, as you can see in the Managing VM checkpoints recipe.

Installing Hyper-V inside Windows Server

Installing Hyper-V on Windows Server 2022 is straightforward, as this recipe demonstrates. Once you have installed it, you can configure the feature.

Getting ready

This recipe uses SRV2, a recently added workgroup host. By default, this host is a DHCP client. You also need two Windows Server instances, HV1 and HV2, online and must have at least one domain controller in the domain up and running. This recipe demonstrates the remote installation and configuration of your Hyper-V servers.

How to do it...

  1. Installing the Hyper-V feature on HV1, HV2
    $SB = { Install-WindowsFeature -Name Hyper-V -IncludeManagementTools } Invoke-Command -ComputerName HV1, HV2 -ScriptBlock $Sb 
  2. Rebooting the servers to complete the installation
    Restart-Computer -ComputerName HV2 -Force Restart-Computer -ComputerName HV1 -Force 
  3. Creating a PSSession with both HV servers (after reboot)
    $S = New-PSSession HV1, HV2 
  4. Creating and setting the location for VMs and VHDs on HV1 and HV2
    $SB = { New-Item -Path C:\VM -ItemType Directory -Force | Out-Null New-Item -Path C:\VM\VHDs -ItemType Directory -Force | Out-Null New-Item -Path C:\VM\VMs -ItemType Directory -force | Out-Null} Invoke-Command -ScriptBlock $SB -Session $S | Out-Null 
  5. Setting the default paths for Hyper-V VM disk/config information
    $SB = { $VMs = 'C:\VM\VMs' $VHDs = 'C:\VM\VHDs' Set-VMHost -ComputerName Localhost -VirtualHardDiskPath $VHDs Set-VMHost -ComputerName Localhost -VirtualMachinePath $VHDs } Invoke-Command -ScriptBlock $SB -Session $S 
  6. Setting NUMA spa...

Table of contents

  1. Preface
  2. Installing and Configuring PowerShell 7
  3. Introducing PowerShell 7
  4. Exploring Compatibility with Windows PowerShell
  5. Using PowerShell 7 in the Enterprise
  6. Exploring .NET
  7. Managing Active Directory
  8. Managing Networking in the Enterprise
  9. Implementing Enterprise Security
  10. Managing Storage
  11. Managing Shared Data
  12. Managing Printing
  13. Managing Hyper-V
  14. Managing Azure
  15. Troubleshooting with PowerShell
  16. Managing with Windows Management Instrumentation
  17. Other Books You May Enjoy
  18. Index

Frequently asked questions

Yes, you can cancel anytime from the Subscription tab in your account settings on the Perlego website. Your subscription will stay active until the end of your current billing period. Learn how to cancel your subscription
No, books cannot be downloaded as external files, such as PDFs, for use outside of Perlego. However, you can download books within the Perlego app for offline reading on mobile or tablet. Learn how to download books offline
Perlego offers two plans: Essential and Complete
  • Essential is ideal for learners and professionals who enjoy exploring a wide range of subjects. Access the Essential Library with 800,000+ trusted titles and best-sellers across business, personal growth, and the humanities. Includes unlimited reading time and Standard Read Aloud voice.
  • Complete: Perfect for advanced learners and researchers needing full, unrestricted access. Unlock 1.5M+ books across hundreds of subjects, including academic and specialized titles. The Complete Plan also includes advanced features like Premium Read Aloud and Research Assistant.
Both plans are available with monthly, semester, or annual billing cycles.
We are an online textbook subscription service, where you can get access to an entire online library for less than the price of a single book per month. With over 1.5 million books across 990+ topics, we’ve got you covered! Learn about our mission
Look out for the read-aloud symbol on your next book to see if you can listen to it. The read-aloud tool reads text aloud for you, highlighting the text as it is being read. You can pause it, speed it up and slow it down. Learn more about Read Aloud
Yes! You can use the Perlego app on both iOS and Android devices to read anytime, anywhere — even offline. Perfect for commutes or when you’re on the go.
Please note we cannot support devices running on iOS 13 and Android 7 or earlier. Learn more about using the app
Yes, you can access Windows Server Automation with PowerShell Cookbook by Thomas Lee in PDF and/or ePUB format, as well as other popular books in Computer Science & Operating Systems. We have over 1.5 million books available in our catalogue for you to explore.