Added Task Scheduler Item System Tasks
This commit is contained in:
parent
c6ea2b8e5e
commit
b9e5155a76
19
Patches/Tasks/System_Tasks.ps1
Normal file
19
Patches/Tasks/System_Tasks.ps1
Normal 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)"
|
||||
}
|
||||
}
|
||||
20
Patches/Windows/Add-System-Sched-Task.ps1
Normal file
20
Patches/Windows/Add-System-Sched-Task.ps1
Normal 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."
|
||||
Loading…
x
Reference in New Issue
Block a user