Remote shutdown, at shutdown

niksal12

Honorable
Oct 10, 2013
28
0
10,530
I have two computers A and B. Both are running windows 7. Computer A is connecter to a battery backup via usb, computer B is powered by the same backup however is not connected via usb. When AC power is lost computer A is told to shutdown. The battery backup software does not support remote shutdown or running a script/batch file. (APC's Powerchute personal edition). I have a batch file that does what I need but I cannot find a way to run it when computer A is told to shut down. Is this possible?
 
Solution
You can probably use PowerShell to query the battery status during shutdown. There are WMI classes for the battery. If the battery state is "discharging," you could run the remote shutdown. I'm going to write a sample script for you later today if I get around to it.

rusabus

Distinguished
May 19, 2007
191
0
18,760
You can probably use PowerShell to query the battery status during shutdown. There are WMI classes for the battery. If the battery state is "discharging," you could run the remote shutdown. I'm going to write a sample script for you later today if I get around to it.
 
Solution

niksal12

Honorable
Oct 10, 2013
28
0
10,530
Thanks so i would have to run that on computer A so that whent the battery state changes it would then send the shutdown command to computer B correct?


 

rusabus

Distinguished
May 19, 2007
191
0
18,760
So, I've found 2 different options. I too have an APC UPS powering 2 computers with PowerChute, but I had to uninstall it to get this first solution to work. I also had to uninstall the APC drivers for the battery backup and use the builtin Windows drivers. You could use this as a shutdown script in PowerShell:
Code:
if ((Get-WmiObject Win32_Battery).BatteryStatus -eq 1) {Stop-Computer -ComputerName "yourRemoteComputer" -Force}
I'm sure the above could be converted to use WMIC instead of powershell, but I leave that up to you :)

The second solution is posted on the APC forums, but I didn't test it. http://forums.apc.com/thread/9055

In my case, neither option really works since my switches are not on a battery backup, just my PCs.

Hope that helps.

--Russel

edit

for kicks, I converted the above PowerShell into a batch file that uses WMIC. It should run faster than the PowerShell variant:
Code:
@echo off
for /f "usebackq skip=1 eol=" %%i in (`wmic path win32_battery get BatteryStatus`) do (
	for /f "tokens=1 delims=:" %%j in ("%%i") do (
		if %%j == 1 (
			echo Battery is discharging
			shutdown /s /m \\computername
		)
	)
)
 

niksal12

Honorable
Oct 10, 2013
28
0
10,530

Awesome thank you, I will have to try these out when i get off work.