Hyper-V 2016 series tutorial 39 using Hyper-V and Windows PowerShell in Windows 10

Source: Internet
Author: User
Tags microsoft website



Note: the following sections are taken from the Microsoft website:



Now that you have a basic understanding of how to deploy Hyper-V, create virtual machines, and manage these virtual machines, let's look at how to use PowerShell to automate most of these activities.


Returns a list of Hyper-V commands
  1. Click the Windows Start button, and type "PowerShell".
  2. powershell
  3. get-command -module hyper-v | out-gridview 

    The contents of the fetch are as follows:

    650) this.width=650; "Src=" https://docs.microsoft.com/zh-cn/ Virtualization/hyper-v-on-windows/quick-start/media/command_grid.png "style=" Border:0px;height:auto;/>

  4. To learn more about specific PowerShell commands, use theGet-Help. For example, run the following command to returnGet-VMinformation about the Hyper-V command.



    PowerShell


    Get-help GET-VM


    The output shows you how to build the command, the required and optional parameter definitions, and the aliases that you can use.



    650) this.width=650; "Src=" https://docs.microsoft.com/zh-cn/virtualization/hyper-v-on-windows/quick-start/media/ Get_help.png "style=" Border:0px;height:auto; "/>


Return to the list of virtual machines


using  GET-VM  command returns the list of virtual machines.


  1. powershell
  2. GET-VM 


    650) this.width=650; "Src=" Https://docs.microsoft.com/zh-cn/virtualization/hyper-v-on-windows/quick-start/media /get_vm.png "style=" Border:0px;height:auto; "/>

  3. To return only the list of virtual machines that have been started, add a filter to theGet-VMcommand. You canWhere-Objectadd filters by using commands. For more information about filtering, see Working with where-object documents.



    PowerShell


    GET-VM | where {$_. State-eq ' Running '}
  4. To list all virtual machines that are in the shutdown state, run the following command. This command is a copy of the command in step 2, but the filter is changed from running to off.
  5. PowerShell

    GET-VM | where {$_. State-eq ' Off '}
To start and shut down a virtual machine
  1. To start a specific virtual machine, run the following command with the virtual machine name:
  2. PowerShell

    Start-vm-name <virtual Machine name>
  3. powershell

    get-vm | where {$_. state -eq  ' Off '}&NBSP;|&NBSP;START-VM 
  4. To close all running virtual machines, run the following command:
  5. PowerShell

    GET-VM | where {$_. State-eq ' Running '} | Stop-vm
To create a VM checkpoint

To create checkpoints using PowerShell, use theGet-VMcommand to select a virtual machine, and then pass the virtual machine through a pipe to theCheckpoint-VMCommand. Finally, use-SnapshotNameName the checkpoint. The complete command looks like this:


PowerShell


Get-vm-name <VM name> | Checkpoint-vm-snapshotname <name for Snapshot>
Create a new virtual machine


The following example shows how to create a new virtual machine in the PowerShell Integrated Scripting Environment (ISE). This is a simple example and can be extended to include additional PowerShell features and more advanced VM deployments.


  1. To open PowerShell Ise, click Start, and type PowerShell ise.
  2. Run the following code to create the virtual machine. ForNew-VMmore information about commands, see the NEW-VM documentation.



    PowerShell


    $VMName = "VMNAME"$VM = @{
      Name = $VMName 
      MemoryStartupBytes = 2147483648
      Generation = 2
      NewVHDPath = "C:\Virtual Machines\$VMName\$VMName.vhdx"
      NewVHDSizeBytes = 53687091200
      BootDevice = "VHD"
      Path = "C:\Virtual Machines\$VMName"
      SwitchName = (Get-VMSwitch).Name[0]
    }New-VM @VM
Summary and Reference


This document describes some simple steps for studying the Hyper-V PowerShell module and some example scenarios. For more information about the Hyper-V PowerShell module, see Hyper-V Cmdlets PowerShell command prompt http://hangyc.blog.51cto.com/2016 series tutorial 427521/1965057






This article is from "Hangzhou Technology blog" blog, please be sure to keep this source http://hangyc.blog.51cto.com/427521/1965724



Hyper-V 2016 series tutorial 39 using Hyper-V and Windows PowerShell in Windows 10


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.