Scheduling a reboot of a server

Store this cmd file script somewhere and schedule it using the system task schedule, it will need to have administrator and “run when user not logged in” rights.

The exported XML file from the scheduled task contains this

<?xml version="1.0" encoding="UTF-16"?>
<Task version="1.2" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
  <RegistrationInfo>
    <Date>2016-01-13T10:41:23.3455701</Date>
    <Author>DOMAIN\adminuser</Author>
  </RegistrationInfo>
  <Triggers>
    <CalendarTrigger>
      <StartBoundary>2016-01-13T02:00:00</StartBoundary>
      <Enabled>true</Enabled>
      <ScheduleByWeek>
        <DaysOfWeek>
          <Sunday />
        </DaysOfWeek>
        <WeeksInterval>1</WeeksInterval>
      </ScheduleByWeek>
    </CalendarTrigger>
  </Triggers>
  <Principals>
    <Principal id="Author">
      <UserId>DOMAIN\adminuser1</UserId>
      <LogonType>Password</LogonType>
      <RunLevel>HighestAvailable</RunLevel>
    </Principal>
  </Principals>
  <Settings>
    <MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy>
    <DisallowStartIfOnBatteries>true</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>
    <WakeToRun>false</WakeToRun>
    <ExecutionTimeLimit>P3D</ExecutionTimeLimit>
    <Priority>7</Priority>
  </Settings>
  <Actions Context="Author">
    <Exec>
      <Command>c:\windows\system32\cmd.exe</Command>
      <Arguments>/c "C:\program files\local\rebootme.cmd"</Arguments>
    </Exec>
  </Actions>
</Task>

the cmd file that logs and performs the actual reboot contains this

 

@set logfile="D:\Logfiles\rebootme.log"
echo %0 >> %logfile%
date /t >> %logfile%
time /t  >> %logfile%
shutdown /r /t 5

About Jeff Turner

Technical director of Nano Tera Network Solutions.
This entry was posted in Powershell, VBS, VBA and other scripting., System Administration. Bookmark the permalink.