Solved

Restart Hyper-V VM from command line/shortcut

Posted on 2013-12-17
4
444 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Sometimes simple is better. :)
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

#Citrix #Citrix Netscaler #HTTP Compression #Load Balance
Veeam Backup & Replication has added a new integration – Veeam Backup for Microsoft Office 365.  In this blog, we will discuss how you can benefit from Office 365 email backup with the Veeam’s new product and try to shed some light on the needs and …
This tutorial will show how to push an installation of Backup Exec to an additional server in both 2012 and 2014 versions of the software. Click on the Backup Exec button in the upper left corner. From here, select Installation and Licensing, then I…
To efficiently enable the rotation of USB drives for backups, storage pools need to be created. This way no matter which USB drive is installed, the backups will successfully write without any administrative intervention. Multiple USB devices need t…

743 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

14 Experts available now in Live!

Get 1:1 Help Now