Need to run a powershell script every time system wakes up from Sleep

Question:

I just finished writing a script with PowerShell and I need it to run every time my system wakes up from sleep or Hibernation.
I tried the gpedit.msc -> User Config -> Windows Settings -> Scripts -> Logon but this does not work when my system Wakes up from ‘Sleep’… probably because ‘Sleep’ – > ‘Wake -up’ is not technically new logon (As a user I am already logged-on).

Either a Sleep-Wake event or Login (User Login) event should trigger my script.

Any ideas on how I can do this?

More Info on what my script does: It checks if internet/network is connected. If yes, it will attempt to run the Cisco VPN connection command line utility with required arguments and logs me into VPN. Every time I wake my system up from sleep and login I need the damn VPN to connect me automatically.

Answer:

I figured it out. I used the Task Scheduler as Richard indicated above.

I set the Trigger as..
On an Event -> System -> Kernel-Power -> 42

If anyone is interested… here is the script (I am a beginner with PowerShell scripts, so welcome your inputs)

Source:

Need to run a powershell script every time system wakes up from Sleep by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply