To configure Hyper-V virtual machine restart automatically using Windows PowerShell

Source: Internet
Author: User

In the actual production environment of the enterprise, especially after the server virtualization is deployed, it is necessary to configure the virtual machine restart automatically, which can reduce the downtime even when the server is in trouble or the scheduled maintenance is complete and the virtual machine can be restarted automatically.

Today's article focuses on configuring virtual machines to automatically restart in a Hyper-V environment using PowerShell.

One, use Windows PowerShell to see that the virtual machine has not been configured to restart automatically

The system's built-in PowerShell allows you to see which auto-start is configured for your virtual machine. Instead of using the right mouse button VM to select Settings to view, use the following PowerShell command on the Hyper-V host and use the Get VM cmdlet to pipeline to the Selection object:

Get-vm–vmname * | Select-object vmname,automaticstartaction

By using the above command, we can not only view the VMS on which they are hosted, but also show whether they are configured to restart automatically

650) this.width=650; "height=" 141 "title=" image "style=" margin:0px;border:0px;padding-top:0px;padding-right:0px; Padding-left:0px;background-image:none; "alt=" image "src=" Http://s3.51cto.com/wyfs02/M02/71/3A/wKioL1XJkoSg_ Tx7aachda10fmw946.jpg "border=" 0 "/>

Ability to discover two virtual machines on the current host and not configured to restart automatically

Second, configure the virtual machine automatic restart

In Hyper-V, Microsoft offers three ways to start a VM self-booting, namely:

1) None-do not perform any action

2) Auto-start (if it is still running when the service is stopped)

3) always automatically restarts the secondary virtual machine

When you choose to start automatically, you can also choose whether to configure for delayed start.

650) this.width=650; "height=" 242 "title=" image "style=" margin:0px;border:0px;padding-top:0px;padding-right:0px; Padding-left:0px;background-image:none; "alt=" image "src=" http://s3.51cto.com/wyfs02/M00/71/3A/ Wkiol1xjkowqsub9aaderqdosmk971.jpg "border=" 0 "/>

Use the following command to configure a virtual machine to start automatically

Get-vm–vmname bj-vmm-01 | Set-vm–automaticstartaction Start

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

650) this.width=650; "height=" title= "image" style= "margin:0px;border:0px;padding-top:0px;padding-right:0px; Padding-left:0px;background-image:none; "alt=" image "src=" http://s3.51cto.com/wyfs02/M02/71/3B/ Wkiol1xjkofhwdg2aaegngr4pyu145.jpg "border=" 0 "/>

If you want to set up all virtual machines on the Hyper-V server to restart automatically, use the following command

Get-vm–vmname * | Set-vm–automaticstartaction Start

Third, configure the virtual machine automatic restart (delay)

If a critical business is running on a Hyper-V server, such as a DC server, a SQL Server, and a System Center server, the services of the SCCM server cannot be started because of the corresponding dependent environment and the SQL database service is not started, so You can configure automatic restart of SQL data, configure the SCCM server to delay startup, and set a delay time (such as 120S)

Get-vm–vmname bj-srv-01 | Set-vm–automaticstartdelay 120

650) this.width=650; "height=" "title=" image "style=" margin:0px;border:0px;padding-top:0px;padding-right:0px; Padding-left:0px;background-image:none; "alt=" image "src=" http://s3.51cto.com/wyfs02/M02/71/3E/ Wkiom1xjkifwyndtaabpavapalq965.jpg "border=" 0 "/>

Use the following command to view the virtual machines that have been configured for delayed startup

Get-vm–vmname * | Select-object Vmname,automaticstartaction,automaticstartdelay

650) this.width=650, "height=" "title=" image "style=" margin:0px;border:0px;padding-top:0px;padding-right:0px; Padding-left:0px;background-image:none; "alt=" image "src=" http://s3.51cto.com/wyfs02/M00/71/3E/ Wkiom1xjkifadbpsaabi4l5qldw203.jpg "border=" 0 "/>

Iv. Configure automatic restart of VMS on multiple Hyper-V hosts

In large data centers where a large number of Hyper-V hosts are deployed, it is unrealistic to log on to each host to be configured for automatic restarts, and it is a requirement to enable the automatic restart of virtual machines on multiple Hyper-V hosts.

Get-vm–computername Sysvh-33-202,sysvh-98-250–vmname * | Select-object Vmname,automaticstartaction,automaticstartdelay

650) this.width=650; "height=" 143 "title=" image "style=" margin:0px;border:0px;padding-top:0px;padding-right:0px; Padding-left:0px;background-image:none; "alt=" image "src=" http://s3.51cto.com/wyfs02/M01/71/3E/ Wkiom1xjkirdjykkaacbxjorkzq294.jpg "border=" 0 "/>

If you have many Hyper-V hosts that need to be configured for virtual machine self-booting, then the following is also a configuration method

$hosts = @{computername = "sysvh-33-201", "SYSVH-33-202GET-VM @hosts –vmname * | Set-vm–automaticstartaction startget-vm @hosts –vmname * | Select-object Vmname,automaticstartaction,automaticstartdelay "}


This article is from "Xu Ting blog-it technology sharing" blog, please be sure to keep this source http://ericxuting.blog.51cto.com/8995534/1683633

To configure Hyper-V virtual machine restart automatically using Windows PowerShell

Related Article

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.