Prevent user from trying to restart or turn off computer

I wrote a powershell script that pushes a payload to a series of remote machines and installs it. The installation will probably take at least 10 minutes. During this time, I don’t want the remote machines to be able to restart or turn off, because that would interrupt the installation process and potentially make me unable to reinstall the application later.

What’s the best way of going about this?

Also, if I use -dontwait on Invoke-Command so I don’t have to wait for each machine to finish its particular installation, is it still possible to receive a return status for each of the installations to ensure they all were successful?

-dontwait parameter ? Can you share the code here ? Invoke-Command doesn’t have that parameter.

My bad, my memory must be foggy. I could have sworn I saw that parameter. Regardless, is it possible to prevent a computer from restarting or shutting down for a period of, say, 5 minutes?

Not sure if there are any setting in windows which will disable restart option, I got a related blog post which might help you. You can do this prior executing the script and undo it back once the installation succeeds.

http://www.itingredients.com/remove-shutdown-start-menu-via-gpo/

As for the root of this.

Prevent user from trying to restart or turn off computer

… this simply cannot be stopped.

You’d have to have code on the system to disable the hardware button on laptops and desktops, and even then, nothing tops the user from yanking the cord out of the wall electrical socket.

It would be more prudent for you to send the user a message notifying them when you plan to take this action, and informing them to not make any attempts to stop it or power off the system.

Gotcha, thank you guys for the information!

And to make that really easy, you can use MSG to create a pop-up dialogue message for all users, like this:

MSG * /SERVER:computername "message text"

This will pop up a box with your message right in the middle of the screen with an OK button. You can also apply a wait-for-user-acknowledgement function or a timeout. This command will work even if PSRemoting is not enabled on the target system, and even though that documentation says it’s for server editions, it also works on Windows desktop as far back as XP.

If you run MSG again, it replaces the previous message box. For your purposes, if you don’t know the exact amount of time your installation will take, you could have the script re-send the message every so often (maybe 10 min intervals) until it completes. It won’t result in a stack of dialogue boxes that need to be closed.