I am attempting to iterate over many task scheduler entries to modify the task arguments. We have many servers running simultaneously launched scripts, all need to be reachable on the console if a process needs attention.
Ideal is to launch minimized with start /min or powershell -window minimized
I am testing against one sample task. My code so far looks like
$PREFIX = "-window minimized"
$taskPath = "\somepath\"
Get-ScheduledTask -CimSession "servername" -TaskPath $taskPath -TaskName "mytask" | ForEach-Object {
$actions = $_.Actions
$actions New-ScheduledTaskAction -Execute "powershell" -Argument "${PREFIX} ${actions}"
Set-ScheduledTask -CimSession "servername" -TaskPath $taskPath -TaskName $_.TaskName -Action $actions
}
This works excepting I cannot get to the old command arguments. Always I get as new arguments with my prefix and then 'MSFT_TaskExecAction' following. This fails against a multi-step task resulting in only one bad step afterwards (and MSFT_TaskExecAction). Thanks all.