Welcome Forums General PowerShell Q&A SchedueledJob Question

Viewing 3 reply threads
  • Author
    Posts
    • #60874
      Participant
      Topics: 5
      Replies: 6
      Points: 56
      Rank: Member

      I am using a great PS script I found to do some Hyper-V backups. As part of it it recommends using a ScheduledJob as follows:

      $trigger = New-JobTrigger -Weekly -DaysOfWeek Friday -At 1:08AM
      $options = New-ScheduledJobOption -RunElevated
      $VMs = "VM1"
      
      #specify script parameter values in order
      Register-ScheduledJob -Name "Weekly VM Export" -FilePath c:\scripts\hypervbackup.ps1 -Trigger $trigger -ScheduledJobOption $options -ArgumentList $VMs,"F:\Hyper-V Exports",$False,$False
      
      $trigger = New-JobTrigger -Weekly -DaysOfWeek Friday -WeeksInterval 4 -At 1:00AM
      #reuse options and vms
      Register-ScheduledJob -Name "Monthly VM Export" -FilePath c:\scripts\hypervbackup.ps1 -Trigger $trigger -ScheduledJobOption $options -ArgumentList $VMs,"F:\Hyper-V Exports",$True,$False
      

      However, the scheduled job never runs. It runs fine when I run it manually.

      I don’t even know where to start. Where can I see any errors about this? What am I doing wrong?

      Thanks in advance for your help on this!

      Paul.

    • #60876
      Participant
      Topics: 2
      Replies: 1752
      Points: 3,621
      Helping Hand
      Rank: Community Hero

      Have you tried checking the created scheduled job? I could imagine that “-FilePath” expects an executable. So if you want to run a Powershell script you should place the path to your powershell.exe in “-FilePath” and put “the rest” of the command to the “-ArgumentList” like this: “-NoProfile -File c:\scripts\hypervbackup.ps1 $VMs,’F:\Hyper-V Exports’,$True,$False”

      It is always recommended to read ALL of the help for the cmdlets you use including the examples.

    • #60894
      Participant
      Topics: 5
      Replies: 6
      Points: 56
      Rank: Member

      well… how does one check the scheduled job? it is listed when query for it.

      the strange thing is that I deployed the same scripts on another server and they did not work… and then one day… they just started working. I tried to figure out why that started working and don’t see anything different.

    • #60900
      Participant
      Topics: 2
      Replies: 376
      Points: 1
      Rank: Member

      you job saved under current user credentials without saved password.
      thus it can run if current user logged into server
      may be ‘start as batch job’ right also involved

Viewing 3 reply threads
  • The topic ‘SchedueledJob Question’ is closed to new replies.