R Mat
R Mat

Reputation: 105

how to import build-in tasks with powershell

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

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

Answers (1)

SE1986
SE1986

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

Related Questions