Last active
January 13, 2017 22:09
-
-
Save vendettamit/c7a011e935634a3a6e7574893ce2e322 to your computer and use it in GitHub Desktop.
Create Event based task to run a custom powershell script on Windows Event
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Create a task to run powershell script on event | |
$cred = Get-Credential | |
$password = $cred.GetNetworkCredential().Password | |
$taskName = "EventMonitoringService" | |
$action = New-ScheduledTaskAction -Execute 'Powershell.exe' -Argument '-NoProfile -WindowStyle Hidden "C:\CourtAlert\Scripts\TakeAction.ps1""' | |
#Remove existing tasks | |
$taskExists = Get-ScheduledTask | Where-Object {$_.TaskName -like $taskName } | |
if($taskExists) { | |
write-host "Unregistering $($taskExists)" | |
Unregister-ScheduledTask -TaskName $taskExists.TaskName -Confirm:$false | |
} | |
SCHTASKS /Create /TN $taskName /TR $action /SC ONEVENT /RL Highest /RU $cred.Username /RP $password /EC Application /MO "*[Application]" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment