SchedueledJob Question

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.

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.

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.

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