Something else you should notes is that Catkiller and I come at the problem from slightly different ways. This is because we have different backgrounds, I'd bet. I'm trained as an ASE, worked in that area for about 5 yrs before transitioning more into software. I come from a Unix admin, programming, huge organization background. We tried to be consistent with management of all the different systems. So I will always prefer the more cross-platform technique to solve issues. sudo is cross-platform. I've never heard of pkexec on anything except Linux. If you can use the Linux-specific solutions, it can work.

Also, I've been burned a few times in scripts when I was lazy and didn't fully specify the path to every command. Someone can change the PATH and bam - a completely different program gets used than the one intended.

In a script, I'd never use this:
Code:
pkexec systemctl reboot --boot-loader-entry=windows
though I might be tempted to use:
Code:
/usr/bin/pkexec  /bin/systemctl  reboot --boot-loader-entry=windows
When you finally get to the point of automating many things via cron, you'll appreciate this slight difference. It is both for security and to avoid future failures. Using the full path so that the PWD/CWD aren't important for any input to a script is a design best practice. We see people NOT doing that here all the time and they have problems with their scripts. Windows allowed end-users not to really know about PWD, which is critical for anyone doing scripting or programming.

Anyways, we've beaten this topic enough. Good luck.