# Function to obtain and evaluate consistant yes/no user response function Get-logicalYesNo([string]$question) { do { $sAnswer = Read-Host "$question [Y/N]" } until ($sAnswer.ToUpper()[0] -match '[yYnN]') return ($sAnswer.ToUpper()[0] -match '[Y]') #return $True or $False } # Define correct executable path, and correct working directory $newExecutablePath = "C:\Program Files\Laserfiche\Workflow\WFScheduleMonitor.exe" # Replace with the current executable path of WFScheduleMonitor.exe $newWorkingDirectory = "C:\Program Files\Laserfiche\Workflow" # Replace with the current working directory where WFScheduleMonitor.exe resides # Create a filter to limit scope to Workflow associated scheduled tasks $taskFilter = "WF*" # the task names typically look like WF8_LFSRVNAME_WF2010_R45 # Get the list of scheduled tasks associated with specified filter $scheduledTasks = Get-ScheduledTask -TaskName $taskFilter Clear # Clear output window of any existing messages Write-Output "The following scheduled tasks will be updated:" Write-Output $scheduledTasks $proceed = Get-logicalYesNo("Do you wish to proceed. [Y]es or [N]o?") if ($proceed) { # Loop through the scheduled tasks foreach ($task in $scheduledTasks) { # Confirm the task exists if ($task) { # Get the current task action and modify it $action = $task.Actions[0] # Assuming there's only one action $action.Execute = $newExecutablePath $action.WorkingDirectory = $newWorkingDirectory # Create the new task settings (preserve the old settings) $taskName = $task.TaskName $taskSettings = $task.Settings $taskTriggers = $task.Triggers $taskPrincipal = $task.Principal # Update the scheduled task with the new action, keeping other settings Set-ScheduledTask -TaskName $taskName -Action $action -Trigger $taskTriggers -Principal $taskPrincipal -Settings $taskSettings | Out-Null Write-Host "Task '$taskName' updated successfully!" } else { Write-Host "Task '$taskName' not found." } } } else { Write-Host "User cancelled - no changes made." }