Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions install.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -316,9 +316,12 @@ if ($AddToPath) {
Write-InstallMessage "Step 5: Skipping PATH addition (use -AddToPath to enable)" -Type Info
}

# Step 6: Install scheduled task (optional)
if ($InstallScheduledTask) {
Write-InstallMessage "Step 6: Installing scheduled task..." -Type Info
# Step 6: Install scheduled task (optional, or auto-update if already installed)
$taskAlreadyExists = Get-ScheduledTask -TaskName "Win-Ops System Cleanup" -ErrorAction SilentlyContinue

if ($InstallScheduledTask -or $taskAlreadyExists) {
$reason = if ($taskAlreadyExists -and -not $InstallScheduledTask) { "updating existing" } else { "installing" }
Write-InstallMessage "Step 6: $(if ($taskAlreadyExists -and -not $InstallScheduledTask) { 'Updating existing scheduled task (auto-detected)...' } else { 'Installing scheduled task...' })" -Type Info

if (-not (Test-IsElevated)) {
Write-InstallMessage "Administrator privileges required for scheduled task installation" -Type Error
Expand All @@ -329,9 +332,9 @@ if ($InstallScheduledTask) {
Import-Module $schedulerModule -Force

Install-WinOpsScheduledTask -Interval $ScheduleInterval -Force
Write-InstallMessage "Scheduled task installed successfully" -Type Success
Write-InstallMessage "Scheduled task $reason successfully" -Type Success
} catch {
Write-InstallMessage "Failed to install scheduled task: $_" -Type Error
Write-InstallMessage "Failed to $reason scheduled task: $_" -Type Error
Write-InstallMessage "You can install it manually later using: Install-WinOpsScheduledTask" -Type Info
}
}
Expand Down
2 changes: 1 addition & 1 deletion scheduler/TaskScheduler.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ function Install-WinOpsScheduledTask {
# Create task action
$action = New-ScheduledTaskAction `
-Execute "pwsh.exe" `
-Argument "-NoProfile -ExecutionPolicy Bypass -File `"$scriptPath`"" `
-Argument "-NoProfile -NonInteractive -WindowStyle Hidden -ExecutionPolicy Bypass -File `"$scriptPath`"" `
-WorkingDirectory $workingDir

# Create task trigger based on interval
Expand Down
2 changes: 1 addition & 1 deletion scheduler/WinOpsTask.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
<Actions Context="Author">
<Exec>
<Command>pwsh.exe</Command>
<Arguments>-NoProfile -ExecutionPolicy Bypass -File "SCRIPT_PATH"</Arguments>
<Arguments>-NoProfile -NonInteractive -WindowStyle Hidden -ExecutionPolicy Bypass -File "SCRIPT_PATH"</Arguments>
<WorkingDirectory>WORKING_DIR</WorkingDirectory>
</Exec>
</Actions>
Expand Down