Skip to content

Commit

Permalink
Update Set-ScheduledTask.ps1 with latest from Immy
Browse files Browse the repository at this point in the history
  • Loading branch information
MWGMorningwood authored Dec 13, 2024
1 parent dfc371e commit 2981f0f
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions Function/Set-ScheduledTask.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -66,21 +66,21 @@ switch ($method) {

#Overall task comparison
Write-Debug "DEBUG: Scheduled task: $task"

Check notice

Code scanning / PSScriptAnalyzer

Line has trailing whitespace Note

Line has trailing whitespace
#Fail condition
if ($null -eq $task) {
Write-Progress -Activity "Testing Scheduled Task" -CurrentOperation "Comparison failed - Task Missing" -Completed -Id 1
return $false
}

$Test_ScriptResult = Test-ScheduledTaskScript

Check notice

Code scanning / PSScriptAnalyzer

Line has trailing whitespace Note

Line has trailing whitespace
$Test_DescResult = ( $task.Description -eq $TaskDesc )
Write-Progress -Activity "Testing Scheduled Task" -CurrentOperation "Description Comparison finished with result: $Test_DescResult" -PercentComplete 80 -Id 1

$TestResult = ( $Test_DescResult -and $Test_ScriptResult )
Write-Progress -Activity "Testing Scheduled Task" -CurrentOperation "Validation finished with result: $TestResult" -Completed -Id 1

Check notice

Code scanning / PSScriptAnalyzer

Line has trailing whitespace Note

Line has trailing whitespace
$TestResult
}

Expand All @@ -91,7 +91,6 @@ switch ($method) {
if(!$Test_ScriptResult){
$Set_ScriptResult = Set-ScheduledTaskScript
Write-Progress -Activity "Setting Scheduled Task" -CurrentOperation "Enforced configured scriptblock" -PercentComplete 50 -Id 2
Write-Host $Set_ScriptResult
}
$result = Invoke-ImmyCommand {
switch ($using:Trigger) {
Expand All @@ -102,7 +101,7 @@ switch ($method) {
}
Write-Debug "DEBUG: Trigger is set to $($using:Trigger)"
Write-Debug "DEBUG: Build Trigger: $buildtrigger"

Check notice

Code scanning / PSScriptAnalyzer

Line has trailing whitespace Note

Line has trailing whitespace
# Check if the task exists and remove it if it does
if (![string]::IsNullOrWhiteSpace($using:task)){
Unregister-ScheduledTask -TaskName $using:TaskName -Confirm:$false
Expand All @@ -125,4 +124,4 @@ switch ($method) {
Write-Host "INFO: Scheduled Task Results:"
return $result
}
}
}

0 comments on commit 2981f0f

Please sign in to comment.