I am trying to register a task in windows task scheduler by reading a XML file as string and able to do it successfully, additionally what i want to do is, to replace the {plname} (which is present in the XML) with the task name.
<Exec>
<Command>notepad.exe</Command>
<Arguments>-Command "&{ & "./pl.ps1 {plname} run" }"</Arguments>
<WorkingDirectory>C:\Windows\System32\Tasks\Power</WorkingDirectory>
</Exec>
When i run my PS script (excluding the Register-ScheduledTask cmdlet) I can see the {plname} being replaced. font is small but you can see {plname} is replaced by openNotepad
Now when I run the "Register-ScheduledTask" cmdlet it registers the task successfully but in the GUI of Task Scheduler it is not showing the replacement done just before. {plname} was replaced earlier with openNotepad, but has reverted back to its previous state.
Hope i have made myself clear. Here is my script, Just in case.
$taskName = "openNotepad"
$taskTemplate = Get-Content (join-path "C:\Users\ACER\Desktop\POWERSHELL" "task-scheduler-template.xml" ) | Out-String
$taskTemplate -replace "{plname}", $taskName
Register-ScheduledTask -Xml $taskTemplate -TaskPath "\Power\" -TaskName $taskName