Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ##############################
- ######## CREATE TASKS ########
- ##############################
- #
- ## ERROR STDOUT PREFERENCE ###
- $ErrorActionPreference = 'silentlycontinue'
- #
- ###### TIME-SPAN VALUE #######
- $TimeSpan = New-TimeSpan `
- -Minutes 3
- #
- ##### WHEN TO RUN TASK #######
- $Trigger = New-ScheduledTaskTrigger `
- -AtLogOn
- #
- ###### TASK OWNER INFO #######
- $Principal = New-ScheduledTaskPrincipal `
- -UserId "$Env:USERDOMAIN\$Env:USERNAME" `
- -LogonType Interactive `
- -RunLevel Highest
- $Settings = New-ScheduledTaskSettingsSet `
- -StartWhenAvailable `
- -AllowStartIfOnBatteries `
- -DontStopIfGoingOnBatteries `
- -Priority 0 `
- -RestartCount 3 `
- -RestartInterval $TimeSpan `
- -ExecutionTimeLimit '00:00:00'
- #
- ###### TASKS FOLDER NAME #####
- $Folder = 'Start-Scripts'
- #
- ######### TASKNAMES ##########
- $TaskName1 = 'start_ahk_multiple_hotkeys'
- $TaskName2 = 'start_ryzen_master'
- $TaskName3 = 'start_corsair_link'
- #
- ###### FOLDER + TASKNAME #####
- $FullTask1 = "$Folder\$TaskName1"
- $FullTask2 = "$Folder\$TaskName2"
- $FullTask3 = "$Folder\$TaskName3"
- #
- ############ AHK #############
- $Action1 = New-ScheduledTaskAction `
- -Execute "$Env:ProgramFiles\AHK\AutoHotkey.exe" `
- -Argument "$Env:OneDrive\Documents\01_Scripts\02_AHK\Multiple_Hotkeys\Hotkeys_1.ahk"
- #
- ########### RYZEN ############
- $Action2 = New-ScheduledTaskAction `
- -Execute "$Env:ProgramFiles\AMD\RyzenMaster\bin\AMD Ryzen Master.exe"
- #
- ##############################
- ######## CORSAIRLINK #########
- ##############################
- $Action3 = New-ScheduledTaskAction `
- -Execute "$Env:ProgramFiles(x86)\CorsairLink4\CorsairLink4.exe"
- #
- ######### IF EXISTS #########
- if((Get-ScheduledTask -TaskName "$FullTask1")){
- Write-Host "$FullTask1" -NoNewline -ForegroundColor Yellow -BackgroundColor Black
- Write-Host " - Already Exists" -ForegroundColor Red -BackgroundColor Black
- }
- else{
- Register-ScheduledTask -TaskPath '\' -TaskName "$FullTask1" -InputObject (
- New-ScheduledTask -Action $Action1 `
- -Principal $Principal `
- -Trigger $Trigger `
- -Settings $Settings
- )
- Write-Host 'A task was created -' -NoNewline -ForegroundColor Yellow -BackgroundColor Black
- Write-Host " - $FullTask1" -ForegroundColor Green -BackgroundColor Black
- }
- #
- ######## IF EXISTS 2 ########
- if((Get-ScheduledTask -TaskName "$FullTask2")){
- Write-Host "$FullTask2" -NoNewline -ForegroundColor Yellow -BackgroundColor Black
- Write-Host " - Already Exists" -ForegroundColor Red -BackgroundColor Black
- }
- else{
- Register-ScheduledTask -TaskPath '\' -TaskName "$FullTask2" -InputObject (
- New-ScheduledTask -Action $Action2 `
- -Principal $Principal `
- -Trigger $Trigger `
- -Settings $Settings
- )
- Write-Host 'A task was created -' -NoNewline -ForegroundColor Yellow -BackgroundColor Black
- Write-Host " - $FullTask2" -ForegroundColor Green -BackgroundColor Black
- }
- #
- ######## IF EXISTS 3 ########
- if((Get-ScheduledTask -TaskName "$FullTask3")){
- Write-Host "$FullTask3" -NoNewline -ForegroundColor Yellow -BackgroundColor Black
- Write-Host " - Already Exists" -ForegroundColor Red -BackgroundColor Black
- }
- else{
- Register-ScheduledTask -TaskPath '\' -TaskName "$FullTask3" -InputObject (
- New-ScheduledTask -Action $Action3 `
- -Principal $Principal `
- -Trigger $Trigger `
- -Settings $Settings
- )
- Write-Host 'A task was created -' -NoNewline -ForegroundColor Yellow -BackgroundColor Black
- Write-Host " - $FullTask3" -ForegroundColor Green -BackgroundColor Black
- }
- #
- ###### EXIT PARAMETERS #######
- Read-Host -Prompt "Press Enter to exit"
Advertisement
Add Comment
Please, Sign In to add comment