Book Image

Windows Server 2016 Automation with PowerShell Cookbook - Second Edition

By : Thomas Lee, Ed Goad
Book Image

Windows Server 2016 Automation with PowerShell Cookbook - Second Edition

By: Thomas Lee, Ed Goad

Overview of this book

This book showcases several ways that Windows administrators can use to automate and streamline their job. You'll start with the PowerShell and Windows Server fundamentals, where you'll become well versed with PowerShell and Windows Server features. In the next module, Core Windows Server 2016, you'll implement Nano Server, manage Windows updates, and implement troubleshooting and server inventories. You'll then move on to the Networking module, where you'll manage Windows network services and network shares. The last module covers Azure and DSC, where you will use Azure on PowerShell and DSC to easily maintain Windows servers.
Table of Contents (21 chapters)
Title Page
Credits
About the Author
Acknowledgment
About the Reviewer
www.PacktPub.com
Customer Feedback
Preface

Managing VM state


Managing the VM state involves stopping and starting or pausing and resuming a VM. You can also save and restore a VM.

Getting ready

This recipe uses the VM1 VM created in the Creating a virtual machine recipe. This recipe assumes the VM1 VM is stopped when you start this recipe. If this VM is running, then first stop it using Stop-VM.

How to do it...

Here is how to manage VM state:

  1. Get the VM's state to check if it is off:
      Get-VM     -Name VM1
  1. Start the VM, get its status, then wait until the VM has an IP address assigned and the networking stack is working, then examine the VM's state:
      Start-VM  -VMName VM1 
      Get-Vm    -VMName VM1 
      Wait-VM   -VMName VM1 -For IPAddress 
      Get-VM    -VMName VM1
  1. Suspend and resume a VM:
      Suspend-VM -VMName VM1 
      Get-VM     -VMName VM1 
      Resume-VM  -VMName VM1 
      Get-VM     -VMName VM1
  1. Save the VM and check status:
      Save-VM    -VMName VM1 
      Get-VM     -VMName VM1
  1. Resume the saved VM and view the...