Advertisement
easternnl

Create Scheduledtask with Powershell

Mar 16th, 2016
577
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $xml = '<?xml version="1.0" encoding="UTF-16"?>
  2. <Task version="1.3" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
  3.  <RegistrationInfo>
  4.    <Date>2016-03-16T14:32:21.0880128</Date>
  5.    <Author>SCCM\SCCM</Author>
  6.  </RegistrationInfo>
  7.  <Triggers>
  8.    <LogonTrigger>
  9.      <Enabled>true</Enabled>
  10.    </LogonTrigger>
  11.  </Triggers>
  12.  <Principals>
  13.    <Principal id="Author">
  14.      <RunLevel>LeastPrivilege</RunLevel>
  15.      <GroupId>BUILTIN\Users</GroupId>
  16.    </Principal>
  17.  </Principals>
  18.  <Settings>
  19.    <MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy>
  20.    <DisallowStartIfOnBatteries>false</DisallowStartIfOnBatteries>
  21.    <StopIfGoingOnBatteries>true</StopIfGoingOnBatteries>
  22.    <AllowHardTerminate>true</AllowHardTerminate>
  23.    <StartWhenAvailable>false</StartWhenAvailable>
  24.    <RunOnlyIfNetworkAvailable>false</RunOnlyIfNetworkAvailable>
  25.    <IdleSettings>
  26.      <StopOnIdleEnd>true</StopOnIdleEnd>
  27.      <RestartOnIdle>false</RestartOnIdle>
  28.    </IdleSettings>
  29.    <AllowStartOnDemand>true</AllowStartOnDemand>
  30.    <Enabled>true</Enabled>
  31.    <Hidden>false</Hidden>
  32.    <RunOnlyIfIdle>false</RunOnlyIfIdle>
  33.    <DisallowStartOnRemoteAppSession>false</DisallowStartOnRemoteAppSession>
  34.    <UseUnifiedSchedulingEngine>false</UseUnifiedSchedulingEngine>
  35.    <WakeToRun>false</WakeToRun>
  36.    <ExecutionTimeLimit>P3D</ExecutionTimeLimit>
  37.    <Priority>7</Priority>
  38.  </Settings>
  39.  <Actions Context="Author">
  40.    <Exec>
  41.      <Command>C:\Program Files\Hewlett-Packard\HP Hotkey Support\QLBController.exe</Command>
  42.    </Exec>
  43.  </Actions>
  44. </Task>'
  45.  
  46.  $schedule = New-Object –ComObject ("Schedule.Service")
  47.  $schedule.connect()
  48.  
  49.  $folder = $schedule.GetFolder("\")
  50.  
  51.  $task = $schedule.NewTask($null)
  52.  $task.XmlText = $xml
  53.  
  54.  $folder.RegisterTaskDefinition("HP Hotkeys", $task, 6, "", "", 1, $null)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement