1

I wasn't able to find anything online, with physical servers I could run something like shutdown /s /f /t 1000 or use task scheduler. What I'm looking to do is shut down a VM but want to shut down the VMs just before the physical is shut down (site will have the power turned off)

Is there a way to achieve this?

Matthew
  • 135
  • 10
  • What prevents you from doing this in your VM? – Lenniey Jan 13 '20 at 12:07
  • There isn't one @Lenniey but it isn't very clean - is there no way to do this via HyperV/the host or do we simply need to run the command via the VM itself? – Matthew Jan 13 '20 at 12:08
  • 1
    https://docs.microsoft.com/en-us/powershell/module/hyper-v/stop-vm?view=win10-ps – Lenniey Jan 13 '20 at 12:11
  • Thanks for that, there doesn't appear to be a time-related parameter, however, it could easily be run via scheduler instead. – Matthew Jan 13 '20 at 12:13
  • It isn't very clean? Using the shutdown command is no different in a VM then it is in a physical machine. – joeqwerty Jan 13 '20 at 12:35
  • @joeqwerty It's not clean in the sense I would need to remote to every single VM and run the command when at times I'll be running hosts with 20+ VMs on them and other times need to do this with multiple hosts. – Matthew Jan 13 '20 at 12:36
  • OK, so it isn't efficient... but it works exactly the same way. I just wanted to make sure I was understanding you. – joeqwerty Jan 13 '20 at 12:37
  • Hm well, you'll always need some loop (or a list, or wildcard, etc.), either over your VMs or your physical servers. PowerShell is much prettier for this, though. – Lenniey Jan 13 '20 at 12:39

1 Answers1

1

Either use task scheduler for a specific point in time, or, for your example, use Start-Sleep combined with Stop-VM (or Suspend-VM), e.g.:

Start-Sleep -s 1000; Stop-VM -Name TestVM [-Force] on your Hyper-V host.

Lenniey
  • 5,220
  • 2
  • 18
  • 29