Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Restart Hyper-V VM from command line/shortcut

Posted on 2013-12-17
4
Medium Priority
?
987 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 2000 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

Simplify Active Directory Administration

Administration of Active Directory does not have to be hard.  Too often what should be a simple task is made more difficult than it needs to be.The solution?  Hyena from SystemTools Software.  With ease-of-use as well as powerful importing and bulk updating capabilities.

Question has a verified solution.

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

If your vDisk VHD file gets deleted from the image store accidentally or on purpose, you won't be able to remove the vDisk from the PVS console. There is a known workaround that is solid.
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 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 course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Suggested Courses

971 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