Hello, I’m trying to change scheduled tasks through powershell.
The condtion must be that the trigger must not have a full path…such as…
function get-tasks ($folders)
{
foreach($folder in $folders)
{
try
{
foreach ($task in $folder.gettasks(""))
{
if(($task.xml -notmatch '.*\\.*') -and $task.xml -notmatch "" )
{
$task.name
}
}
get-tasks ($folder.getfolders(""))
}
catch
{
get-tasks ($folder.getfolders(""))
}
}
}
#creates an object for task sched
$sched = New-Object -ComObject schedule.service
$sched.connect("Localhost")
#starts the function to scan
$schedissues = @(get-tasks $sched.getfolder(""))
Where $schedissues would return, say: UPnPHostConfig
I would then drill down on that task
[xml]$x = get-content "C:\Windows\System32\Tasks\Microsoft\Windows\UPnP\UPnPHostConfig" #$z = sc.exe $x.Task.Actions.Exec.Command = $z $x.Task.Actions.Exec.Command = "%SystemRoot%\system32\$z"
But it seems if I change the xml through powershell in this fashion it corrupts the task.
Is there a way to achieve this? Would it be easier to save the task’s XML and delete the task and reimport it once it’s changed?
I can only use V2 of powershell for these tasks, unfortunately.