her34
her34

Reputation: 1

Powershell: how to pause or delay or block shutdown to give time for cleanup tasks?

I have a powershell script that is running all the time on windows 7. If user does computer shutdown or reboot, I need a little time to do cleanup tasks such as updating log file.

Is there a way to delay shutdown from within script?

Solutions I've found from searching don't work well: *Listening for events such as SessionEnding are too late and powershell is closed before script has time to do anything

*I'm looking for a solution within the script that runs at startup instead of separate solution such as adding a 2nd script to group policy that runs on shutdown

I've looked at WM_QUERYENDSESSION but I can't get it to work for powershell script.

Upvotes: 0

Views: 1200

Answers (1)

DKU
DKU

Reputation: 75

Add the script on GPE on your local computer, So the script will run while shutdown.

Upvotes: 0

Related Questions