Reputation: 105
Im trying to import task with Powershell and getting this error BTW using import in Task Scheduler is working fine
CMDLINE: PS C:\windows\system32> Register-ScheduledTask -Xml "C:\Windows\System32\Tasks\Microsoft\Windows\TextServicesFramework\MsCtfMonitor" -TaskName "MsCtfMonitor"
Error: Register-ScheduledTask : The task XML is malformed. (1,2)::ERROR: incorrect document syntax At line:1 char:1
+ CategoryInfo : NotSpecified: (PS_ScheduledTask:Root/Microsoft/...S_ScheduledTask) [Register-ScheduledTask], CimException
+ FullyQualifiedErrorId : HRESULT 0x8004131a,Register-ScheduledTask
edit another solution that might help in other cases: powershell -command "& { Register-ScheduledTask -Xml ([System.Io.File]::ReadAllText('C:\Windows\System32\Tasks\Microsoft\Windows\TextServicesFramework\MsCtfMonitor')) -TaskName 'MsCtfMonitor' }"
Upvotes: 1
Views: 3186
Reputation: 2760
You need to pass the actual text of the xml, rather than just the file path:
Register-ScheduledTask -Xml (Get-Content ("C:\Windows\System32\Tasks\Microsoft\Windows\TextServicesFramework\MsCtfMonitor") | Out-String ) -TaskName "MsCtfMonitor"
Upvotes: 3