PowerShell

How to Create a PowerShell Update System for Help Files

One of the best new features in PowerShell v3 is the ability to update help files. This means you can periodically run a command and download the most current versions from Microsoft. The command is easy enough although it must be run in an elevated session.

​PS C:\> Update-Help

This will go through all the modules on your computer and download (and install) the latest help files. Note that as of this writing there are still a number of modules that don’t have downloadable help so the cmdlet will throw a few exceptions, which you can safely ignore. All in all, this works great for you, but what about other PowerShell users and admins? The default behavior is to download from Microsoft, but why have ten people make the same trip? The solution is to save help files once locally and then update from there. Here’s how I’m going to implement a single source help solution in my test network.

Saving Help

The first step is to save the latest help files locally. I’m going to create a network share on my NAS device that will be widely available in my environment. Next, I’ll use the Save-Help cmdlet to download help files to my share.

​PS C:\> Save-Help -DestinationPath \\jdh-nvnas\files\PowerShell_Help

This will get all of the modules on my computer running Windows 8, and save all help files to the share. Eventually everyone will download from this share, which will lead to some potential gaps. If another machine has an installed module that I don’t have, that module’s help files won’t be downloaded. It is possible for that user to download help for only that module from Microsoft or a vendor, but it would need to be a separate step. Otherwise I would need to identify those machines with additional modules and run this command from them as well.

Sponsored Content

What is “Inside Microsoft Teams”?

“Inside Microsoft Teams” is a webcast series, now in Season 4 for IT pros hosted by Microsoft Product Manager, Stephen Rose. Stephen & his guests comprised of customers, partners, and real-world experts share best practices of planning, deploying, adopting, managing, and securing Teams. You can watch any episode at your convenience, find resources, blogs, reviews of accessories certified for Teams, bonus clips, and information regarding upcoming live broadcasts. Our next episode, “Polaris Inc., and Microsoft Teams- Reinventing how we work and play” will be airing on Oct. 28th from 10-11am PST.

Scheduling Updates

It is impossible to say how often help files will get updated. In fact, Update-Help by default limits you to one update every 24 hours unless you use –Force. Even so, periodically I need to refresh the help files on the network share. So why not create a scheduled task? However, since I’m running PowerShell v3, I’m going to create a scheduled job.

A scheduled job creates a scheduled task, but it can also be managed from PowerShell with the traditional job cmdlets. There is also a way to create a scheduled task with Powershell, but that requires Windows 8 or Windows Server 2012, and you might be running PowerShell v3 on Windows 7. A scheduled job will work just fine. Here’s the code I plan on using; you can also download Help task from the site.

​$HelpPath= "\\jdh-nvnas\files\PowerShell_Help"

$TaskName="Download PowerShell v3 Help"

#when to run the task

$trigger = New-JobTrigger -Daily -At 6:00AM

#define a scriptblock

#This command is NOT taking any cultures into account

$Action={Param([string]$Path) Save-Help -DestinationPath $Path -Force}

#define some options

$option = New-ScheduledJobOption -RunElevated -RequireNetwork

#get a credential

$cred = Get-Credential -UserName "$env:userdomain\$env:username" -Message "Enter a credential for the network share $helppath"

#create the scheduled job under Microsoft\Windows\PowerShell\SchedJobs

Register-ScheduledJob -Name $Taskname -Trigger $Trigger -ScriptBlock $Action -ArgumentList $HelpPath -ScheduledJobOption $option

 

I’m going to create a scheduled job that will run at 6 a.m. every day, which will save help to my network share. Help is culture sensitive, and I’m not taking any other cultures into account other than EN-US. There seem to be some culture-related issues with updatable help as of this writing anyway so I’ll use this until those issues are resolved.

Again, I am running this on my computer because I know it is almost always on. But you may want to run it on a server; perhaps even the file server where you are storing the files. If that’s the case, you can use a local path and not the UNC. My command is also specifying a credential. You may or may not need it for the scheduled task to have access to network resources.

After I run this code, I will have a new task in Task Scheduler.

Powershell Help System Task Scheduler

If I don’t want to wait until the next day to start it, I can do it on demand. But after the download, my network share has all the files I need.

 

Powershell Help Network Share

Help files are stored compressed so this shouldn’t take more than a few megabytes of storage. Next, we’re going to update the clients.

Updating Help

To update help from my new share, I will still use Update-Help, except now I specify an alternate source.

​PS C:\> Update-Help –source \\jdh-nvnas\files\PowerShell_Help

 

But I don’t want to have to remember to do this. The easy solution is to put this line in my PowerShell profile script. Every time I start PowerShell the command will run, but it will only update help if it has been 24 hours since I last attempted the update.

An alternative is to use a PowerShell function I wrote that stores the last update time in the registry. If the current time is more than 24 hours since the last update time and after the scheduled update for that day, then help content is downloaded. I’m not going to go through the code itself, but you can download Update-PowerShellHelp. The function has help and the code is documented.

 

Powershell Update Help Download

I’ve set some default values for the function which you can modify. Then you can add a line like this to your PowerShell profile.

​. c:\scripts\Update-PowerShellHelp.ps1

Update-PowerShellHelp

Now I can run Update-PowerShellHelp and it will always check the local source without having to specify it. My function also supports –Whatif.

Summary

Updatable help will be a terrific feature in PowerShell v3. The pieces are in place to manage it in a corporate or team environment, but you have to put them together yourself. My solution is not necessarily the only one — you might use it as inspiration for your own.

If you have questions on updatable help or other PowerShell topics, please stop by the forums at PowerShell.org.

Related Topics:

External Sharing and Guest User Access in Microsoft 365 and Teams

This eBook will dive into policy considerations you need to make when creating and managing guest user access to your Teams network, as well as the different layers of guest access and the common challenges that accompany a more complicated Microsoft 365 infrastructure.

You will learn:

  • Who should be allowed to be invited as a guest?
  • What type of guests should be able to access files in SharePoint and OneDrive?
  • How should guests be offboarded?
  • How should you determine who has access to sensitive information in your environment?

Sponsored by:

 
Live Webinar: Active Directory Security: What Needs Immediate Priority!Live on Tuesday, October 12th at 1 PM ET

Attacks on Active Directory are at an all-time high. Companies that are not taking heed are being punished, both monetarily and with loss of production.

In this webinar, you will learn:

  • How to prioritize vulnerability management
  • What attackers are leveraging to breach organizations
  • Where Active Directory security needs immediate attention
  • Overall strategy to secure your environment and keep it secured

Sponsored by: