windowspowershellwindows-task-scheduler

How to set an author when creating a Windows scheduled task via PowerShell


I'm creating a Window scheduled task using PowerShell. I can't find how to add the Author name. Register-ScheduledTask has a parameter for the description but not for the author.

Exported Windows task:

 <RegistrationInfo>
    <Date>2016-05-17T16:45:54.3423362</Date>
    <Author>NEED TO SET THIS</Author>
    <URI>RunLauncherTask</URI>
  </RegistrationInfo>

Code that a i use for create the task

$principal = New-ScheduledTaskPrincipal -UserId (Get-CimInstance -ClassName Win32_ComputerSystem | Select-Object -expand UserName)
$allTasks = Get-ScheduledTask | Select TaskName
$action = New-ScheduledTaskAction -Execute "C:\Launcher.exe"
$trigger = New-ScheduledTaskTrigger -AtLogOn
$task = New-ScheduledTask -Action $action -Trigger $trigger -Principal $principal
$username = $principal.UserId
$taskName = 'RunLauncherTask' +  $username.Replace('\','-')
$settings = New-ScheduledTaskSettingsSet -DontStopIfGoingOnBatteries -AllowStartIfOnBatteries
Register-ScheduledTask $taskName -Action $action -Settings $settings

How do I set the author?


Solution

  • The only way I know to do this is via the -xml option.

    The option takes the actual string, not a file name.

    $xml = @"
    ....
    ....
    "@
    Register-ScheduledTask -Xml $xml -TaskName $task_name