Function: New-PSUpdateHelpScheduledTask – Auto Update PowerShell Help
Probably not of much value to people unless you build a fair amount of servers and have it scripted, but…
One thing you want to do with servers running PowerShell v3.0, such as Windows Server 2012, is to regularly run Update-Help from a PowerShell session to update the help files PowerShell uses for various modules. But this is something that can be easily forgotten, and, who wants to manually do a recurring task, anyways?
Here is a function you can toss in your server build script to create a scheduled task that will automatically update PowerShell help every day at 7pm. The task runs as ‘system’, so we don’t have to worry about storing credentials. Here’s the function
function New-PSUpdateHelpScheduledTask {
$TaskArguments = '-NonInteractive -WindowStyle Normal -NoLogo -NoProfile -Command "& {Update-Help -Force}"'
$TaskProgram = "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe"
$TaskAction = New-ScheduledTaskAction -Execute $TaskProgram -Argument $TaskArguments
$TaskTrigger = New-ScheduledTaskTrigger -Daily -At 19:00
Register-ScheduledTask -TaskName "Update PowerShell Help" -Action $TaskAction -Trigger $TaskTrigger -RunLevel Highest -User "system"
} # end function New-PSUpdateHelpTask
and merely call it using
New-PSUpdateHelpScheduledTask You'll notice a new scheduled task in Task Scheduler, and we see that it completed successfully. <a href="http://www.ehloworld.com/wp-content/uploads/2013/02/Update-PowerShell-Help.png"><img class="alignnone size-medium wp-image-1732" alt="Update PowerShell Help" src="http://www.ehloworld.com/wp-content/uploads/2013/02/Update-PowerShell-Help-300x195.png" width="300" height="195" /></a>
Just a couple of lines of code and we’ve removed the need to manually run Update-Help on a server.
But what if you don’t use a script to build your servers (you really should)? We can take the code within the function and just paste it into PowerShell:
$TaskArguments = '-NonInteractive -WindowStyle Normal -NoLogo -NoProfile -Command "& {Update-Help -Force}"'
$TaskProgram = "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe"
$TaskAction = New-ScheduledTaskAction -Execute $TaskProgram -Argument $TaskArguments
$TaskTrigger = New-ScheduledTaskTrigger -Daily -At 19:00
Register-ScheduledTask -TaskName "Update PowerShell Help" -Action $TaskAction -Trigger $TaskTrigger -RunLevel Highest -User "system"
Hope this helps!




Follow Me