Run Powershell Script upon Network Connection

Do you handle any scripting with batch still? No?!

Do you need to make a scheduled task using schtasks.exe that runs a PS script in a hidden window every time a network connection is made? No?!


Here is a one line cmd batch script for adding exactly that!

schtasks /create /tn "Net-Connected" /tr "powershell -executionpolicy bypass -file '%SYSTEMDRIVE%\example.ps1'" /SC ONEVENT /EC Microsoft-Windows-NetworkProfile/Operational /MO "*[System[Provider[@Name='Microsoft-Windows-NetworkProfile'] and EventID=10000]]" /RU "System" /F

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: