2
0

Added Task Scheduler Item System Tasks

This commit is contained in:
scarrington 2025-01-16 10:08:23 -06:00
parent c6ea2b8e5e
commit b9e5155a76
2 changed files with 39 additions and 0 deletions

View File

@ -0,0 +1,19 @@
# Specify the directory containing the scripts
$scriptDirectory = "C:\Scripts\Login\System_Tasks"
# Get all Batch scripts in the directory
$scriptsToRun = Get-ChildItem -Path $scriptDirectory -Filter "*.bat"
# Iterate through the script paths and execute each one
foreach ($script in $scriptsToRun) {
try {
# Execute the script
& "$($script.FullName)"
# Add a delay or other actions between scripts if needed
Write-Host "Script '$script' executed successfully."
Start-Sleep -Seconds 5 # Adjust the delay as needed
} catch {
Write-Warning "Error executing '$script' $($_.Exception.Message)"
}
}

View File

@ -0,0 +1,20 @@
$newTaskName = "System_Tasks"
$action = New-ScheduledTaskAction -Execute "powershell.exe" -Argument "-File C:\Scripts\Patches\Tasks\System_Tasks.ps1"
$principal = New-ScheduledTaskPrincipal -UserId "SYSTEM" -RunLevel Highest
$trigger = New-ScheduledTaskTrigger -AtLogon
# Register the new task
Register-ScheduledTask -TaskName $newTaskName -Action $action -Principal $principal -Trigger $trigger
# Get the task and modify settings
$task = Get-ScheduledTask -TaskName $newTaskName
$task.Settings.ExecutionTimeLimit = "PT1H"
$task.Settings.Hidden = $true
# Update the task in-place
$task | Set-ScheduledTask
# Output messages
Write-Host "New task '$newTaskName' created with startup trigger."
Write-Host "Task '$newTaskName' will stop after 1 hour of execution."
Write-Host "Task '$newTaskName' is hidden."