Solved

Restart Hyper-V VM from command line/shortcut

Posted on 2013-12-17
4
665 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

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

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

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 article provides a convenient collection of links to Microsoft provided Security Patches for operating systems that have reached their End of Life support cycle. Included operating systems covered by this article are Windows XP,  Windows Server…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
In this video tutorial I show you the main steps to install and configure  a VMware ESXi6.0 server. The video has my comments as text on the screen and you can pause anytime when needed. Hope this will be helpful. Verify that your hardware and BIO…
Suggested Courses

630 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