This topic contains 3 replies, has 3 voices, and was last updated by
December 27, 2016 at 9:13 pm #60874ParticipantPoints: 0Rank: 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!
December 27, 2016 at 9:54 pm #60876ParticipantPoints: 1,176Rank: 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.
December 28, 2016 at 1:09 am #60894ParticipantPoints: 0Rank: 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.
December 28, 2016 at 6:56 am #60900ParticipantPoints: 0Rank: 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
The topic ‘SchedueledJob Question’ is closed to new replies.