When was Update-Help last run?

This topic contains 5 replies, has 4 voices, and was last updated by Profile photo of Roy Barton Roy Barton 3 days, 3 hours ago.

  • Author
    Posts
  • #35175
    Profile photo of Tony Pagliaro
    Tony Pagliaro
    Participant

    I'm just curious f there's a way to tell when the last time the Update-Help cmdlet was run. If I knew this, I could put in my profile something like...
    if ($update.date -lt 1 week) {update-help}

    I could do it every wednesday or something, but i open/close PS many times daily.

    I could drop a breadcrumb, such as a text file exists and was last modified on this date... and that would do it, but i'd like to know if PS has this feature already for me to use.

    Thanks 🙂

  • #35176
    Profile photo of Don Jones
    Don Jones
    Keymaster

    If you don't use -Force, there's already an "only once per 24 hours" behavior, so running it multiple times per day without -Force isn't so bad. Otherwise, I'm not sure where the countdown clock is kept. You could certainly just store your own value somewhere, though, and trigger off that.

  • #35177
    Profile photo of Tony Pagliaro
    Tony Pagliaro
    Participant

    Oh cool, that 24-hour thing is the missing piece... thanks again, Don!

  • #35294
    Profile photo of Nagendra Narembally
    Nagendra Narembally
    Participant

    You can schedule it like below so that it updates every week on a specified day & time.

    Register-ScheduledJob -Name UpdateHelpJob -Credential Domain01\User01 -ScriptBlock {Update-Help} -Trigger (New-JobTrigger -Daysofweek Thursday -At "5 PM")

  • #36926
    Profile photo of Tony Pagliaro
    Tony Pagliaro
    Participant

    Hey Don,
    I noticed today that the Update-Help ran multiple times, each time I opened ISE or the console. I closed it and reopened it and sure enough, the update help runs again, even though it had just run.

    Is the 24-hour limit a feature in a newer version? Is there some global variable I can check for the run behavior?

    Here's what I have in my profile, that should only run on Wednesdays but not more than once a day (per your advice).

    # Update-Help will only run once per 24h, unless the -Force flag is used. 
    if ((get-date).DayOfWeek -eq 'Wednesday') {Update-Help}
    

    [EDIT]:
    Hi Nagendra, I just tried your method and it was missing the "-Weekly" mandatory parameter. Thanks, it looks OK when run with that. How would I ensure the help is up to date? I guess that brings it around full circle huh?

  • #59581
    Profile photo of Roy Barton
    Roy Barton
    Participant

    I put this in my $profile

    $isupdated = (Get-Item 'C:\Windows\SysWOW64\WindowsPowerShell\v1.0\en-US\').LastWriteTime.Day
    $today = (Get-Date).Date.Day
        If (($isupdated) -eq ($today))
            {
            Write-Host "Powershell help files were updated today."
            }
        else
        {
            Write-Host "Updating Powershell help files.."
            Update-Help
        }
    

You must be logged in to reply to this topic.