From fbe2385207962993e69d6487f46c8d862cd43353 Mon Sep 17 00:00:00 2001 From: romanitho <96626929+Romanitho@users.noreply.github.com> Date: Mon, 9 Oct 2023 15:17:24 +0200 Subject: [PATCH] optimization --- Winget-AutoUpdate/Winget-Upgrade.ps1 | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Winget-AutoUpdate/Winget-Upgrade.ps1 b/Winget-AutoUpdate/Winget-Upgrade.ps1 index cbe2684..d078670 100644 --- a/Winget-AutoUpdate/Winget-Upgrade.ps1 +++ b/Winget-AutoUpdate/Winget-Upgrade.ps1 @@ -321,6 +321,9 @@ if (Test-Network) { $task = New-ScheduledTask -Action $taskAction -Principal $taskUserPrincipal -Settings $taskSettings Register-ScheduledTask -TaskName 'Winget-AutoUpdate-UserContext' -TaskPath 'WAU' -InputObject $task -Force | Out-Null Write-ToLog "-> User Context task created." + + #Load it + $UserContextTask = Get-ScheduledTask -TaskName 'Winget-AutoUpdate-UserContext' -ErrorAction SilentlyContinue } #User check routine from: https://stackoverflow.com/questions/23219718/powershell-script-to-see-currently-logged-in-users-domain-and-machine-status @@ -335,7 +338,7 @@ if (Test-Network) { #Run user context scheduled task Write-ToLog "Starting WAU in User context..." - Get-ScheduledTask -TaskName "Winget-AutoUpdate-UserContext" -ErrorAction SilentlyContinue | Start-ScheduledTask -ErrorAction SilentlyContinue + $null = $UserContextTask | Start-ScheduledTask -ErrorAction SilentlyContinue Exit 0 } }