The below PWSH code works wonderfully to keep a physical display turned off if one is physically in front of a Windows 10 device and logged in (displays turning on spuriously is a totally different problem but hey, one thing at a time).
However, what I'd like to do is run a script so that when one is remoted into a Windows 10 device, the physical display remains off (although the remote desktop display is still visible in the remote desktop client), regardless of initially making the remote desktop connection, maintaining the connection, or disconnecting from the remote session for any reason.
Also, please no non-answer responses (e.g. "Why don't you just do XYZ instead?", "I haven't tested it myself but, 'BLAH BLAH BLAH'.", "Why do you want to do that?", etc.).
Add-Type -TypeDefinition ' using System; using System.Runtime.InteropServices;