Criar tarefa agendada a partir de arquivo xml por arquivo em lote

Criar tarefa agendada a partir de arquivo xml por arquivo em lote

Eu tenho uma tarefa agendada em minha máquina de teste. A máquina de teste é win 7. Exporto a tarefa em xml e estou tentando criar uma nova tarefa de agendamento semelhante, pois terei que criar a mesma tarefa de agendamento em mais de 500 máquinas.

Estou planejando criar um arquivo em lote para tarefa agendada. Como a maioria das máquinas está no mesmo domínio. Então, estou planejando usar uma conta de serviço para autenticação.

Abaixo está o arquivo xml. Isso está funcionando bem no momento no agendador de tarefas.

<?xml version="1.0" encoding="UTF-16"?>
<Task version="1.3" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
  <RegistrationInfo>
    <Date>2016-01-26T19:26:36.6011086</Date>
    <Author>test\404</Author>
    <Description>Testing Tasks</Description>
  </RegistrationInfo>
  <Triggers>
    <CalendarTrigger>
      <Repetition>
        <Interval>PT1H</Interval>
        <Duration>P1D</Duration>
        <StopAtDurationEnd>false</StopAtDurationEnd>
      </Repetition>
      <StartBoundary>2016-01-26T19:25:42.7621086</StartBoundary>
      <EndBoundary>2017-01-26T19:25:43.0101086</EndBoundary>
      <Enabled>true</Enabled>
      <ScheduleByDay>
        <DaysInterval>1</DaysInterval>
      </ScheduleByDay>
    </CalendarTrigger>
  </Triggers>
  <Principals>
    <Principal id="Author">
      <UserId>test\404</UserId>
      <LogonType>Password</LogonType>
      <RunLevel>LeastPrivilege</RunLevel>
    </Principal>
  </Principals>
  <Settings>
    <MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy>
    <DisallowStartIfOnBatteries>false</DisallowStartIfOnBatteries>
    <StopIfGoingOnBatteries>true</StopIfGoingOnBatteries>
    <AllowHardTerminate>true</AllowHardTerminate>
    <StartWhenAvailable>false</StartWhenAvailable>
    <RunOnlyIfNetworkAvailable>false</RunOnlyIfNetworkAvailable>
    <IdleSettings>
      <StopOnIdleEnd>true</StopOnIdleEnd>
      <RestartOnIdle>false</RestartOnIdle>
    </IdleSettings>
    <AllowStartOnDemand>true</AllowStartOnDemand>
    <Enabled>true</Enabled>
    <Hidden>false</Hidden>
    <RunOnlyIfIdle>false</RunOnlyIfIdle>
    <DisallowStartOnRemoteAppSession>false</DisallowStartOnRemoteAppSession>
    <UseUnifiedSchedulingEngine>false</UseUnifiedSchedulingEngine>
    <WakeToRun>false</WakeToRun>
    <ExecutionTimeLimit>PT1H</ExecutionTimeLimit>
    <Priority>7</Priority>
  </Settings>
  <Actions Context="Author">
    <Exec>
      <Command>copier.bat</Command>
      <WorkingDirectory>D:\test\</WorkingDirectory>
    </Exec>
  </Actions>
</Task>

Quando tento criar uma tarefa de agendamento semelhante usando o comando abaixo.

schtasks /create /tn "alarm3" /xml "Test Task.xml"

estou recebendo erro ERRO: Falha de logon: nome de usuário desconhecido ou senha incorreta.

Quero saber como posso criar tarefas agendadas usando arquivo em lote. A tarefa de agendamento precisa ser compatível paraGanhe 2003paraGanhe servidor 2012.

Obrigado pelo seu tempo.

Responder1

Você pode usar schtaskse fornecer as credenciais do usuário da tarefa. Eu uso isso regularmente em meus scripts do PowerShell

schtasks.exe /create /s NAMEOFCOMPUTER /ru DOMAIN\USER /rp PASSWORD /tn NAMEOFTASK' /XML PATHTOXMLFILE

informação relacionada