Solved

Restart Hyper-V VM from command line/shortcut

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

A safe way to clean winsxs folder from your windows server 2008 R2 editions
In this article, I will show you HOW TO: Perform a Physical to Virtual (P2V) Conversion the easy way from a computer backup (image).
This tutorial will walk an individual through the steps necessary to enable the VMware\Hyper-V licensed feature of Backup Exec 2012. In addition, how to add a VMware server and configure a backup job. The first step is to acquire the necessary licen…
This tutorial will walk an individual through the steps necessary to install and configure the Windows Server Backup Utility. Directly connect an external storage device such as a USB drive, or CD\DVD burner: If the device is a USB drive, ensure i…

861 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now