$taskName = "CortexAgent" $pythonPath = "C:\CortexAgent\venv\Scripts\python.exe" $mainPath = "C:\CortexAgent\src\agent_node\main.py" $logPath = "C:\CortexAgent\agent.log" $action = New-ScheduledTaskAction -Execute "cmd.exe" -Argument "/c `"$pythonPath $mainPath >> $logPath 2>&1`"" $principal = New-ScheduledTaskPrincipal -UserId "SYSTEM" -LogonType ServiceAccount -RunLevel Highest $settings = New-ScheduledTaskSettingsSet -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries -StartWhenAvailable Unregister-ScheduledTask -TaskName $taskName -Confirm:$false -ErrorAction SilentlyContinue Register-ScheduledTask -TaskName $taskName -Action $action -Principal $principal -Settings $settings Start-ScheduledTask -TaskName $taskName