title: Why can't this script make a scheduled task event through Powershell script?
body: <p>I've run into a small problem with a script I've been working on. </p>
  
  <p>The code itself works perfectly fine; when I run it on my local workstation, it's perfect. However, when I run it on one of the servers (Win 2003 R2 32-bit) that need SCCM installed on it (which this script is designed to automatically install) it fails in one of my functions. Relevent code follows:</p>
  
  <pre><code>    # Schedules Weekly tasks
      function SchWeekly
      {param ([string]$Comp, [string]$Date, [string]$RunTime, [int]$DayOfWeek, [string]        $commandpath)
  
      $service = new-object -comobject "Schedule.Service"             # Forms object reference
      $service.Connect($Comp)                                         # Connects to host machine
      $rootFolder = $service.GetFolder("\")                       # Sets root folder of Task Scheduler
      $taskDefinition = $service.NewTask(0)                           # Begins task creation
      $regInfo = $taskDefinition.RegistrationInfo                     # Sets registry info
      $regInfo.Description = 'SCCM Check For Update'
      $regInfo.Author = "Administrator"
      $settings=$taskDefinition.Settings                              # Sets default settings for the new task
      $settings.StartWhenAvailable = $True
      $settings.Hidden = $False
      $triggers = $taskDefinition.Triggers                            # Creates Trigger object reference
      $trigger = $triggers.Create(3)                                  # Sets to create (Number 3 means Weekly trigger)
      # Start Time ex. 2012-6-10 22:00:00
      $trigger.StartBoundary = $Date + "T" + $RunTime                 # Sets start date (End date can be set) e
                                                              # ex. $trigger.EndBoundary = Date + "T" + Time
      $trigger.DaysOfWeek = $DayOfWeek                                # Sends integer for day of week to run on (1-7)
                                                              # 1 = Sunday, 2 = Monday, etc....
      $trigger.WeeksInterval = 1                                      # Sets to run every week
      $trigger.Id = "WeeklyTriggerId"                                 # Trigger ID name
      $trigger.Enabled = $True
      $Action = $taskDefinition.Actions.Create(0)
      $Action.Path = $commandpath                                         # Links to script
      $rootFolder.RegisterTaskDefinition('SCCM Check For Update', $taskDefinition, 6, "", "", 3)  # Registers scheduled task
      }
  </code></pre>
  
  <p>The error specifically is on this line:
          $service = new-object -comobject "Schedule.Service"</p>
  
  <p>It reports that "Cannot load COM type Schedule.Service" </p>