Using Hyper-V Server PowerShell

Source: Internet
Author: User

This article mainly demonstrates the simple management of Hyper-V server through the built-in PowerShell by using a different approach to the simple initial configuration of Hyper-V server.

Windows PowerShell is a scripted solution for automating tasks in Windows Server. However, in previous versions of Windows Server, scripting Hyper-V with the self-contained tools, you must learn that WMI,WMI provides a very flexible set of interfaces designed for developers. IT pros who are involved in virtualization need to have other ways of not having to learn the skills of the developer and are able to easily automate a large number of administrative tasks.

Windows PowerShell new Hyper-V cmdlets are designed specifically for IT pros that allow them to perform tasks that can be performed in the graphical user interface of Hyper-V Manager, and there are some tasks that are only available through Windows PowerShell CMDlet to execute.

Hyper-V cmdlets make IT easier for IT pros to think about tasks in terms of the tasks they actually want to perform. The following shows the task and the associated CMDlet syntax.

Task

PowerShell commands for performing tasks

Create a new virtual machine named "bj-ap-01"

New-vm–name bj-ap-01

Get the full list of virtual machines

Get-vm

Create a new virtual hard disk D:\VHDs\BJ-AP-01.vhd

New-vhd–path D:\VHDs\BJ-AP-01.vhd

Start all virtual machines with a name starting with "BJ"

Start-vm–name bj*

Connect the virtual network adapter on the "bj-ap-01" virtual machine to the "LAB" switch

Connect-vmnetworkadapter–vmname Bj-ap-01–switchname LAB

To use the new Hyper-V CMDlet, you have the following requirements:

1) Windows Server 2012/R2

2) The server CPU must support hardware virtualization

3) Hyper-V role

4) have effective permissions to manage Hyper-V servers

However, to manage Hyper-V Server R2, you must use the PowerShell Ise in Windows 8.1 or Windows Server R2, and you cannot manage it using the lower version of PowerShell Ise. This is primarily done by using PowerShell ISE for remote management of Hyper-V Server R2.

Here is a brief introduction to several commonly used hyper-V PowerShell

1. First enter "PowerShell Ise" in PowerShell, or enter "PowerShell ise" in "Run", then the PowerShell Ise will be opened. Then select the new Remote PowerShell tab in the File and a dialog box appears, where you click the Connect button.

650) this.width=650; "height=" "title=" clip_image001 "style=" margin:0px;border:0px;padding-top:0px; Padding-right:0px;padding-left:0px;background-image:none, "alt=" clip_image001 "src=" http://s3.51cto.com/wyfs02/ M02/54/2a/wkiol1r66nvqlyk3aacz83f9wha421.jpg "border=" 0 "/>

650) this.width=650; "height=" 295 "title=" clip_image003 "style=" margin:0px;border:0px;padding-top:0px; Padding-right:0px;padding-left:0px;background-image:none, "alt=" clip_image003 "src=" http://s3.51cto.com/wyfs02/ M00/54/2b/wkiol1r66ocbbbgbaac-os8iswa214.jpg "border=" 0 "/>

650) this.width=650; "height=" 184 "title=" clip_image004 "style=" margin:0px;border:0px;padding-top:0px; Padding-right:0px;padding-left:0px;background-image:none, "alt=" clip_image004 "src=" http://s3.51cto.com/wyfs02/ M01/54/2b/wkiol1r66ogchtp6aacz5hqxtjw130.jpg "border=" 0 "/>

After you click Connect, type a valid account password to connect to the server "bj-hc-01".

650) this.width=650; "height=" "title=" clip_image006 "style=" margin:0px;border:0px;padding-top:0px; Padding-right:0px;padding-left:0px;background-image:none, "alt=" clip_image006 "src=" http://s3.51cto.com/wyfs02/ M02/54/2b/wkiol1r66obsrre2aab2vztm60s334.jpg "border=" 0 "/>

2. Setting up the Hyper-V Server virtual hard disk storage location

By default, all Hyper-V-related configuration files are stored in the

"C:\Users\Public\Documents\Hyper-V\Virtual hard disks\". So it is usually necessary to modify the Hyper-V related configuration file to another path or storage server, using PowerShell to modify the Hyper-V virtual hard disk storage location, which can be modified using the following path:

Set-vmhost-virtualharddiskpath "C:\Hyper-V\VHD"

650) this.width=650; "height=" 109 "title=" clip_image008 "style=" margin:0px;border:0px;padding-top:0px; Padding-right:0px;padding-left:0px;background-image:none, "alt=" clip_image008 "src=" http://s3.51cto.com/wyfs02/ M00/54/2b/wkiol1r66ofickvqaab8gv_bu0k037.jpg "border=" 0 "/>

3. Setting up the Hyper-V Server virtual machine storage location

Virtual hard disks are placed in the default location without specifying the storage folder for the virtual machine

"C:\ProgramData\Microsoft\Windows\Hyper-V\", use PowerShell to modify the Hyper-V virtual hard disk storage location, for example, you can set this location to C:\Hyper-V\VM, if you do not have this folder, The system is created automatically.

Set-vmhost-virtualmachinepath "C:\Hyper-v\VM"

650) this.width=650, "height=", "title=" clip_image010 "style=" margin:0px;border:0px;padding-top:0px;padding-right : 0px;padding-left:0px;background-image:none; "alt=" clip_image010 "src=" http://s3.51cto.com/wyfs02/M01/54/2B/ Wkiol1r66oncbmzhaaa4annoj14820.jpg "border=" 0 "/>

4. Set NUMA spanning

Non-Uniform Memory access (NUMA) is a computer memory design for multiple processors, and memory access time depends on where the processor accesses the memory. Under NUMA, the processor accesses its own local memory faster than the non-local memory (the processor or memory shared between the memory and the other processor), and if the NUMA spanning feature of the server needs to be turned on, in the Hyper-V host setting "Numa spanning" option, you can tick the " Allow virtual machines to span physical NUMA nodes.

650) this.width=650; "height=" 204 "title=" clip_image012 "style=" margin:0px;border:0px;padding-top:0px; Padding-right:0px;padding-left:0px;background-image:none, "alt=" clip_image012 "src=" http://s3.51cto.com/wyfs02/ M02/54/2b/wkiol1r66pkjprheaadx6cb4fvs667.jpg "border=" 0 "/>

The following commands are set up to allow virtual machines to span physical NUMA nodes through the PowerShell command:

Set-vmhost-numaspanningenabled $true

650) this.width=650; "height=" 104 "title=" clip_image014 "style=" margin:0px;border:0px;padding-top:0px; Padding-right:0px;padding-left:0px;background-image:none, "alt=" clip_image014 "src=" http://s3.51cto.com/wyfs02/ M00/54/2b/wkiol1r66pbgkho3aacadgkr5u8166.jpg "border=" 0 "/>

The command to set the shutdown virtual machine across the physical NUMA node through the PowerShell command is as follows:

Set-vmhost-numaspanningenabled $false

650) this.width=650; "height=" 107 "title=" clip_image016 "style=" margin:0px;border:0px;padding-top:0px; Padding-right:0px;padding-left:0px;background-image:none, "alt=" clip_image016 "src=" http://s3.51cto.com/wyfs02/ M01/54/2b/wkiol1r66pmsbcjdaacc0i-wwbi101.jpg "border=" 0 "/>

5. Set up Live migration

In order to optimize the use of physical resources and to facilitate the addition of new virtual machines, you must be able to migrate VMs at any time when needed-without disrupting your business. Windows Server R2 introduces a live migration that migrates a running virtual machine from one physical computer to another, without downtime or service disruption. However, this feature requires that virtual hard disks of the virtual machine remain consistent on the shared storage device, for example, on Fibre Channel or iscsis an. Starting with Windows Server 2012, live migration is no longer limited to clustering, and virtual machines can be migrated across cluster boundaries, including migrating to any Hyper-V home Server in the environment. Hyper-V adds support for parallel live migration on top of this feature, so you can migrate multiple virtual machines at the same time. Combined with network virtualization, this feature even enables easy migration of virtual machines between the local host and the Cloud host.

Hyper-V Live Migration supports migrating a running virtual machine from one physical host to another, without impacting the availability of virtual machines in the middle of a virtual user. Windows Server 2012 begins Hyper-V to introduce faster concurrent live migrations that can be migrated inside and outside the cluster environment. In addition to providing live migration in the most basic deployments, this feature supports more advanced scenarios, such as real-time migration of virtual machines between multiple independent clusters to balance the load across the database.

650) this.width=650; "height=" 261 "title=" clip_image018 "style=" margin:0px;border:0px;padding-top:0px; Padding-right:0px;padding-left:0px;background-image:none, "alt=" clip_image018 "src=" http://s3.51cto.com/wyfs02/ M02/54/2b/wkiol1r66qczekrjaaeawsgmqkw396.jpg "border=" 0 "/>

When you use PowerShell for live migration settings, the hosts that need to be migrated must have the same domain or the same trusted network, and the delegated account must be a member of the Administrators group and require a specific network design. Here's a quick introduction to using PowerShell to simply turn this feature on, and for Hyper-V live migration, there will be a separate space.

Use the command enable-vmmigration to initiate an incoming and outgoing live migration. You will be prompted to "cannot send live migration of the virtual machine to the destination host because no migration network is specified for the incoming Live migration"

650) this.width=650; "height=" 104 "title=" clip_image020 "style=" margin:0px;border:0px;padding-top:0px; Padding-right:0px;padding-left:0px;background-image:none, "alt=" clip_image020 "src=" http://s3.51cto.com/wyfs02/ M00/54/2b/wkiol1r66qoa6wtyaabx0kog7yo816.jpg "border=" 0 "/>

Network support for incoming live migration of hyper-V servers:

Live migration with any available network

Set-vmhost-useanynetworkformigration $true

650) this.width=650; "height=" 103 "title=" clip_image022 "style=" margin:0px;border:0px;padding-top:0px; Padding-right:0px;padding-left:0px;background-image:none, "alt=" clip_image022 "src=" http://s3.51cto.com/wyfs02/ M01/54/2b/wkiol1r66q-snxwmaab0j2iyl2g477.jpg "border=" 0 "/>

Specify these IP addresses for live migration

Set-vmhost-useanynetworkformigration 192.168.100.0/24

650) this.width=650; "height=" 102 "title=" clip_image024 "style=" margin:0px;border:0px;padding-top:0px; Padding-right:0px;padding-left:0px;background-image:none, "alt=" clip_image024 "src=" http://s3.51cto.com/wyfs02/ M02/54/2b/wkiol1r66rhsbuwaaab9nufuq6a499.jpg "border=" 0 "/>

By default, the number of concurrent live migration virtual machines can be 2 concurrently, but it is often possible to migrate in real time in large quantities. Set the number of concurrent implementation migrations with the following command

Set-vmhost-maximumvirtualmachinemigrations 20

650) this.width=650; "height=" 104 "title=" clip_image026 "style=" margin:0px;border:0px;padding-top:0px; Padding-right:0px;padding-left:0px;background-image:none, "alt=" clip_image026 "src=" http://s3.51cto.com/wyfs02/ M00/54/2b/wkiol1r66rjtdlq_aab5rlgraiu927.jpg "border=" 0 "/>

A storage migration is the transfer of files from a virtual machine to another place, and during the transfer, the virtual machine remains operational without downtime. Hyper-V Server Squadron Storage Migration requires only the number of concurrent storage migrations to be provisioned. Set the number of parallel implementation storage migrations with the following command

Set-vmhost-maximumstoragemigrations 10

650) this.width=650; "height=" 121 "title=" clip_image028 "style=" border:0px;padding-top:0px;padding-right:0px; Padding-left:0px;background-image:none, "alt=" clip_image028 "src=" http://s3.51cto.com/wyfs02/M01/54/2B/ Wkiol1r66rvwbpajaackwixvkwm226.jpg "border=" 0 "/>

This article is from the "Xu Ting blog" blog, make sure to keep this source http://ericxuting.blog.51cto.com/8995534/1584793

Using Hyper-V Server PowerShell

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.