Making the Power Button Work
In desktop versions of Windows, pressing the power button will cause the system to commence a graceful shutdown and attempt to close all programs.
However in Windows Server 2012r2, Microsoft has changed the way the physical power button works. If there are any other logged in users, or if the screen is locked, or if there is an unsaved file, or if there are almost any other minor things, then the power button will not work.
This results in administrators doing hard reboots by holding the power button for 10 seconds, or even pulling out the power plug. This is dangerous to the system as it can easily cause data corruption.
While the correct method is to log into the server, not all servers have consoles, and if there are many servers, then this can take a long time. If the servers need to be powered down in an emergency, then there may not be time to log into each server and shut them down manually.
There is a solution on ServerFault: https://serverfault.com/questions/534042/windows-2012-how-to-make-power-button-work-in-every-cases. Here is the solution from this link:
The fact you can't power down a 2012 server when a session is locked is probably by design. I faced a similar need and don't know any policy or registry change to allow that.
I used a simple trick: I captured the power button event which simply run my favorite shutdown.exe with the desired parameters after a timeout.
If you use the correct shutdown parameters, you won't be blocked by open programs.
To capture events, just open the task scheduler and create a task triggered on the desired event ID.
The event in my case is a basic event with these properties Log: System, Source: Kernel-Power, Event-ID: 109
The command I use is: shutdown /s /t 10 /d p:0:0
Other useful information:
Make sure you're logged in as a local administrator to add the Scheduled Task.
When creating the Scheduled Task,
Choose "Run whether user is logged on or not".
Tick "Do not store password. The task will only have access to local computer resources".
Tick "Run with highest privileges".
To make things easier, here is an export of the scheduled task that can be simply imported into Task Scheduler. After importing, you many need to change the user to the local administrator.