2

Background:

We're running a couple of Virtual servers in Hyper-V at a small office using Windows 2008 R2. We only have 1 physical host (and we aren't planning to change that any time soon). We're looking to move to Hyper-V Server 2012.

Currently we have a small UPS that keeps the server running for about 20 minutes and then sends a shutdown message to Windows 2008. The UPS Connects via USB. Windows 2008 recognises the UPS as a battery and there is also software from Eaton that we use to monitor the battery. When Windows shuts down it also shuts down the VM's properly.

We don't want the overhead of running a full version of Server 2012 just so we can have the UPS shut the server down, but we don't want Active Directory and Exchange to suddenly power off either.

Can we make Hyper-V Server 2012 shutdown the VM's gracefully when the UPS runs out of power?

Greg
  • 463
  • 2
  • 12
  • 23
  • 2
    I don't understand the question. You have a W2K8R2 Hyper-V server. You have a UPS connected to this server. During a power outage the UPS signals this server to shut down and this server initiates a shutdown of the VM's. Why wouldn't you just configure the W2K12 Hyper-V host the same way? – joeqwerty Jan 09 '13 at 05:22
  • We currently have Windows 2008 R2 Standard running the Hyper-V service. Looking to migrate to W2k12 Hyper-V Server (running Hyper-V on bare metal) and want to know if we can still do the same thing? – Greg Jan 09 '13 at 05:32
  • Check it - depends on the UPS but at the end nothing really was removed in this area. – TomTom Jan 09 '13 at 06:43
  • @TomTom I was hoping to avoid building the box just to check it and if it doesn't work then I need to rebuild it to a full version of Server 2012 – Greg Jan 11 '13 at 00:40
  • 1
    @joeqwerty he is planning (I THINK) on not using windows server 2012 which would be needed to accomplish what you are saying. I THINK he's is switch over to hyper-v server 2012. – tony roth Apr 05 '13 at 15:12

3 Answers3

1

Hyper-V Server is, at least in these respects, the same as Windows Server installed as "Server Core," which is to say, without a graphical user interface. Whether or not your UPS monitoring stuff works in that environment will depend on whether the software from Eaton can run in an environment without a GUI, and whether you're comfortable configuring these things with command-line tools.

I would suggest calling Eaton to ask them.

Jake Oshins
  • 5,146
  • 18
  • 15
  • the difference between the two is quite significant in one regard, windows server can be switched between non gui to gui mode. But he does not want to use windows server 2012. – tony roth Apr 05 '13 at 15:14
  • Additionally you can install and uninstall the GUI in Server 2012 any time - so no need for reinstalling ... –  Apr 05 '13 at 15:07
  • 1
    hyper-v server 2012 does not have this capability, windows server 2012 does. hyper-v server 2012 is free windows server 2012 is not. – tony roth Apr 05 '13 at 15:10
  • I agree with your answer but isn't asking them to call eaton the same as just pointing users to an online support document which usually ends up with a bunch of down votes... As in it does not add anything to the conversation? – tony roth Apr 05 '13 at 16:25
0

I found out there is an event on every power loss. It is possible to attach shutdown script on that event.

enter image description here

My script

$continue = $true
while($continue){
   $batt = (Get-CimInstance -ClassName Win32_Battery)
   if ($batt.BatteryStatus -eq 2){
      $continue = $false
   } elseif ($batt.BatteryStatus -eq 1 -and $batt.EstimatedChargeRemaining -le 70){
      $continue = $false
      & "C:\Windows\System32\shutdown.exe" /s /t 60 /d u:6:12
   } else {
      Start-Sleep -s 60
   }
}
Alew
  • 101
0

The solution I ended up going with was to create a VBScript that runs on startup (using cscript and Task Scheduler).

The script:

set wmi = GetObject("winmgmts:{impersonationLevel=impersonate,(Shutdown)}!\\.\root\cimv2")
set batteryColl = wmi.ExecQuery("select * from Win32_Battery")
set osColl = wmi.ExecQuery("select * from Win32_OperatingSystem")

while true
 for each battery in batteryColl
  battery.Refresh_
  if battery.batteryStatus = 1 and battery.EstimatedChargeRemaining <= 25 then
   for each os in osColl
    os.Win32Shutdown 5
   next
  end if
 next
 wscript.Sleep 15000
wend

Credit:https://social.technet.microsoft.com/Forums/windowsserver/en-US/5cea0070-55f0-4f0e-b727-222203bf0463/hyperv-core-and-ups

Greg
  • 463
  • 2
  • 12
  • 23