how to import build-in tasks with powershell

0

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

  • Register-ScheduledTask -Xml "C:\Windows\System32\Tasks\Microsoft\Wind ...
  •   + CategoryInfo          : NotSpecified: (PS_ScheduledTask:Root/Microsoft/...S_ScheduledTask) [Register-ScheduledTask], CimException
      + FullyQualifiedErrorId : HRESULT 0x8004131a,Register-ScheduledTask
    
windows
powershell
asked on Stack Overflow Jan 18, 2021 by R Mat

1 Answer

1

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"
answered on Stack Overflow Jan 18, 2021 by SEarle1986

User contributions licensed under CC BY-SA 3.0