I have a script that needs to do some cleanup whenever a shutdown or restart is happening. It essentially only removes 2 files and renaming 2 other files when the shutdown happens.
I tried using these:
$sysevent = [microsoft.win32.systemevents]
Register-ObjectEvent -InputObject $sysevent -EventName "SessionEnding" -Action { #Do cleanup }
Register-ObjectEvent -InputObject $sysevent -EventName "SessionEnded" -Action { #Do cleanup }
But it doesn't seem to be working
How can make it, so that it kicks in the cleanup whenever a shutdown or restart happens?