In the previous post it has the instruction on how to keep the local console open. However, it doesn’t work well for Windows Server 2012.
Somehow when you remote desktop the machine, the task in Task Scheduler is triggered. It is not only triggered at disconnection, but also connection of a remote session. It looks like a bug.
To work around the issue, the action to be run needs to know if it is at connection or disconnection. The command query session can find out. Then the command tscon is run conditionally.
Create a command batch, say, named opensession.cmd.
query session | find ">rdp-tcp"
if %errorlevel%==1 tscon 1 /dest:console
In the task action, let it start the batch file.