Update-Help for disconnected machines


PowerShell 3.0 and above do not contain any in-box help files, so when you run Get-Help it will display the auto-generated help syntax based on the cmdlet’s metadata (same as using Get-Command with the -Syntax switch) and will prompt you to use the Update-Help cmdlet to download the help files. As soon as the help files are installed, Get-Help will display the help, just as it did in previous versions.

But what do you do when you want to update the help files on a computer that doesn’t have Internet connectivity? Simply:

1. Run the Update-Help cmdlet on a machine that does have Internet connectivity:

Update-Help

 

2. Run the Save-Help with the -Destination parameter:

$TargetPath = ‘C:\Temp\myHelpFiles’

New-Item -Path $TargetPath -ItemType Directory | Out-Null

Save-Help -DestinationPath $TargetPath

 

3. Copy the output folder (C:\Temp\myHelpFiles) to a thumb-drive or burn it onto a CD.

4. Copy it to the “disconnected machine”.

5, Run the Update-Help cmdlet, with the -SourcePath parameter:

Update-Help -SourcePath C:\Temp\myHelpFiles

 

And that’s it!

Note: You can copy the folder to a UNC path available to all you machines in your disconnected environment, and set it as the default folder for the help updating using GPO. This way, you can have all your disconnected machines automagically point to that folder instead of trying to access the internet when they run Update-Help without the -SourcePath parameter.

The GPO setting is located at: Computer Configuration > Policies > Administrative Templates > Windows Components > Windows PowerShell > “Set the default source path for Update-Help.”

 

But… this will update the help files for the modules installed on the machine that is connected to the internet. What if the disconnected machine has modules that the connected machine doesn’t?

For this, you will have to trick the connected machine’s Update-Help cmdlet to think it has the modules you want to update the help for:

1. From the disconnected machine, run the following:

$TargetPath = ‘C:\StubModulesFolder’

Get-Module -ListAvailable | Where-Object { $_.HelpInfoUri } | ForEach-Object {

    if(Test-Path -Path $($_.ModuleBase)\*helpinfo.xml”) {

        $ModuleFolder = $_.Name

        New-Item -Path $TargetPath\$ModuleFolder -ItemType Directory `

             -ErrorAction SilentlyContinue -Force | Out-Null

        Copy-Item -Path $($_.ModuleBase)\*.psd1″ -Destination $TargetPath\$ModuleFolder -Force

    }

}

 

The code above will create a folder (C:\StubModulesFolder) with several subfolders containing the psdm1 files from each module that can have it’s help updated. These are the files required to “trick” the connected machine to think it has those modules installed.

2. Copy the folder to the connected machine (e.g. C:\StubModulesFolder), and update the $PSModulePath environment variable, to include it in the list of folders where PowerShell looks for available modules:

$val = [environment]::GetEnvironmentVariable(‘PSModulePath’, ‘machine’)

$val = ‘C:\StubModulesFolder;’ + $val

[environment]::SetEnvironmentVariable(‘PSModulePath’, $val, ‘machine’)

 

3. Then you can run through the instructions described in the previous section (steps 1 to 5), and it will get you the updated help for the modules you need.

4. Don’t forget to remove the StubModulesFolder from the $PSModulePath environment variable on the connected machine when you’re done:

$val = [environment]::GetEnvironmentVariable(‘PSModulePath’, ‘machine’)

$val = $val -replace [regex]::Escape(‘C:\StubModulesFolder;’)

[environment]::SetEnvironmentVariable(‘PSModulePath’, $val, ‘machine’)

 

Note: The procedure explained above is a workaround, and it is not the supported way of updating the help files for modules not installed on the machine.

 

HTH,

\Martin.

 

Related reading:

Understanding and Using Updatable PowerShell Help – Hey, Scripting Guy! Blog – Site Home – TechNet Blogs:
https://blogs.technet.microsoft.com/heyscriptingguy/2012/08/31/understanding-and-using-updatable-powershell-help/

Where is PowerShell Updatable Help for Windows Modules? – Hey, Scripting Guy! Blog – Site Home – TechNet Blogs:
http://blogs.technet.com/b/heyscriptingguy/archive/2012/09/24/where-is-powershell-updatable-help-for-windows-modules.aspx

Comments (0)

Skip to main content