locked
Facing issue when Register-SCheduledJob with Trigger RRS feed

  • Question

  • Hi,

    I am creating a scheduled job on a remote machine. I am facing issue with defining trigger. I want that job to be executed at the system startup. For that what I am doing is 

    $trigger = New-JobTrigger -AtStartup

    Register-ScheduledJob -FilePath $TargetforConnectionFile -Trigger $trigger -Name AutoConnect -RunNow -ArgumentList (XXXXXX)

    When I run this script I am getting an error 

    Cannot bind parameter 'Trigger'. Cannot convert value "Microsoft.PowerShell.ScheduledJob.ScheduledJobTrigger" to type "Microsoft.PowerShell.ScheduledJob.ScheduledJobTrigger". Error: "Cannot convert the "Microsoft.PowerShell
    .ScheduledJob.ScheduledJobTrigger" value of type "Deserialized.Microsoft.PowerShell.ScheduledJob.ScheduledJobTrigger" to type "Microsoft.PowerShell.ScheduledJob.ScheduledJobTrigger"

    Can you please suggest what is the problem with my script. If I write triiger as a hashtable like

    Register-ScheduledJob –FilePath \\Srv01\Scripts\Update-Version.ps1 –Trigger @{Frequency=Weekly; At="9:00PM"; DaysOfWeek="Monday"; Interval=2} –ScheduledJobOption @{WakeToRun; StartIfNotIdle; MultipleInstancesPoli
        cy="Queue"}

    This works perfectly fine.

    Can anybody please suggest me how to write AtStartup inside the Register-ScheduledJob itself i.e. as Hashtable?

    Thanks & Regards,
    Girish 

    Wednesday, September 13, 2017 11:54 AM

Answers

  • Hi Girish,

    interesting serialization issue, makes me want to look at the source code.

    Either way, the hashtable should probably look like this:

    @{ Frequency = "AtStartup" }

    Cheers,
    Fred


    There's no place like 127.0.0.1

    • Marked as answer by Girish Nehte Wednesday, September 13, 2017 12:27 PM
    Wednesday, September 13, 2017 12:14 PM