Scheduled jobs - book error?

This topic contains 2 replies, has 3 voices, and was last updated by Profile photo of Dave Wyatt Dave Wyatt 3 years, 10 months ago.

  • Author
    Posts
  • #7862
    Profile photo of Bryan Sciotto
    Bryan Sciotto
    Participant

    From chapter 15 section 9 of  "... Powershell 3 in a month of lunches" I was getting a different result than what the book was stating.

    The command is: (no issue with the command)

    Register-ScheduledJob -Name DailyProcList -ScriptBlock {Get-Process} -Trigger (New-JobTrigger -Daily -At 2am) -ScheduledJobOption (New-ScheduledJobOption -WakeToRun -RunElevated)

    My issue is with the following:

    The book says "Unlike normal jobs, receiving the results from scheduled jobs won’t delete the results, because they’re cached on disk and not in memory. You can continue to receive the results over and over."

    I ran get-job to see that the job has run and there is data. Next I tired receiving the data from the job using  "receive-job -Name DailyProcList " and the data was displayed as expected.

    Here is the issue, get-job now shows this job as having no more data available. Running "receive-job -Name DailyProcList" again returns nothing. So I checked the  xml file on the disk and there is data. Side note import-clixml doesn't work when trying to read the data but I could be doing something wrong there.

    I do know about the  -keep switch and will continue to use it but I just wanted to know if was doing something wrong or this was a typo in the book.

    Thanks

     

  • #7873
    Profile photo of Don Jones
    Don Jones
    Keymaster

    That's standard job behavior. Unless you specify -Keep, Receive-Job can only receive once. PSScheduledJobs are meant to be a bit different, I believe – I'll need to look more specifically – I don't have a copy of the book right in front of me – and do make sure you're using the PSScheduledJob module.

    CliXML is a specific format. It can't read any XML successfully except its own. Job data isn't stored in CliXML.

  • #7876
    Profile photo of Dave Wyatt
    Dave Wyatt
    Moderator

    According to the "about_Scheduled_Jobs" help file:

    Even though the Receive-Job command did not include the Keep parameter,
    the results of the job are saved on disk until you delete them or the
    maximum number of results are exceeded.

    The job results are no longer available in this session, but if you
    start a new session or open a new Windows Powershell window, the
    results of the job are available again.

You must be logged in to reply to this topic.