Solved

Restart Hyper-V VM from command line/shortcut

Posted on 2013-12-17
4
610 Views
Last Modified: 2014-11-12
I have a client with a really old server in a VM and when the app hangs, the only thing to fix it is a reboot. I wanted to set up a shortcut on the desktop of the server to have them click on that and have the VM restart.

What would such a shortcut look like?
0
Comment
Question by:mvalpreda
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 19

Expert Comment

by:jss1199
ID: 39724855
Paste the below powershell command in notepad and save the file with a ps1 extension.

restart-computer -computername <computer>

Open in new window


To create a shortcut:

1. In Windows Explorer, create a new shortcut. It doesn’t matter what your shortcut’s target is, as we’ll change that momentarily.
2. Right-click on your new shortcut, and choose “Properties”.
3. Change the shortcut’s Target to the following:
%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy Bypass -File "C:\Scripts\MyScript.ps1"

Open in new window

4. Be sure to update the path above to where you saved the ps script.
0
 
LVL 5

Accepted Solution

by:
Recept earned 500 total points
ID: 39725529
Depending how old the VM is it may not have Powershell installed. In that case you can use the shutdown command.

Create a shortcut with the target

Windows 2000/2003
shutdown.exe -r -t 00

Open in new window


Windows 2008+
shutdown.exe /r /t 00

Open in new window


/r is reboot
/t is time (in seconds)

If you don't want the shutdown to be immediate you can change the 00 above to another value. Also if you want to force the reboot to close any running applications add a /f
0
 
LVL 6

Expert Comment

by:Bxoz
ID: 39736126
from the Hyper-v server

Example 1

Performs a hard restart of virtual machine TestVM. This is equivalent to turning off the power to the virtual machine and then restarting it.
PS C:\> Restart-VM TestVM

Example 2

Shuts down virtual machine TestVM through the guest operating system.
PS C:\> Stop-VM –Name TestVM
PS C:\> Start-VM –Name TestVM
0
 
LVL 2

Author Closing Comment

by:mvalpreda
ID: 39763579
Sometimes simple is better. :)
0

Featured Post

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Restoring deleted objects in Active Directory has been a standard feature in Active Directory for many years, yet some admins may not know what is available.
Giving access to ESXi shell console is always an issue for IT departments to other Teams, or Projects. We need to find a way so that teams can use ESXTOP for their POCs, or tests without giving them the access to ESXi host shell console with a root …
This tutorial will walk an individual through the steps necessary to join and promote the first Windows Server 2012 domain controller into an Active Directory environment running on Windows Server 2008. Determine the location of the FSMO roles by lo…
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles to another domain controller. Log onto the new domain controller with a user account t…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question