My virtual lab is disconnected from the real Internet so there’s no way to run Update-Help
and get the latest help files. Thankfully there’s Save-Help
which can be used to download the help files on another machine and then transfer them over.
By default Save-Help
only downloads help files for modules installed on the machine it’s run on. That doesn’t cut it for me because my host machine (where I run Save-Help
) doesn’t have as many modules as my guest machines. You can specify the names of modules to download help files for, but simply specifying the names does not work.
1 2 3 4 5 6 7 8 |
PS> Save-Help -Module NFS -DestinationPath C:\Users\Rakhesh\Downloads\temp Save-Help : No Windows PowerShell modules were found that match the following pattern: NFS. Verify the pattern and then try the command again. At line:1 char:1 + Save-Help -Module NFS -DestinationPath C:\Users\Rakhesh\Downloads\temp + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidArgument: (NFS:String) [Save-Help], Exception + FullyQualifiedErrorId : ModuleNotFound,Microsoft.PowerShell.Commands.SaveHelpCommand |
That’s because Save-Help
looks for the module in files stored under the PSModulePath
environment variable (example output from my machine below).
1 2 3 4 5 |
PS> $Env:PSModulePath -split ";" C:\Users\Rakhesh\Documents\WindowsPowerShell\Modules C:\Program Files\WindowsPowerShell\Modules C:\Windows\system32\WindowsPowerShell\v1.0\Modules\ C:\Program Files (x86)\Microsoft SDKs\Azure\PowerShell\ServiceManagement |
So what one really needs to do is provide the module itself to Save-Help
. You have many options here: (1) install the module on the computer (not what you want to do usually!) or (2) connect to a computer which has the module, save that module object in a variable, and pass that on to Save-Help
(you can do an Invoke-Command
, or a New-PSSession
, or a New-CimSession
to the remote machine, then issue the Get-Module -ListAvailable -Name ...
cmdlet to get the module object and pass back to the computer you are on) (see the first example from the Save-Help
help page for more on this).
In my case since the host machine (with Internet) and guest machine (which needs the updated help files) have no network connection between them I’ll have to resort to other means. Enter Export-CliXML
and Import-CliXML
. When you connect to a remote machine and store the module object in a variable, what’s happening behind-the-scenes is that the object is converted to a text representation in XML. This preserves all the properties of the object but not the methods, and once this XML is passed to the remote computer it is converted back to an object (without the methods of course). If you can remote to a machine all this happens behind the scenes, but you can also do this manually via the Export-CliXML
and Import-CliXML
cmdlets – convert all the module objects on the target computer to their XML representation, copy these XML files to the computer with Internet access, convert them back to modules and download help files, then copy these help files to the target computer so Update-Help
can add.
Thus on the virtual machine I do something like this:
1 2 3 |
foreach ($module in $(Get-Module -ListAvailable)) { Export-Clixml -Path C:\Users\rakhesh\Downloads\$module -InputObject $module } |
Copy them to the host, change to that directory, and run:
1 2 3 4 |
foreach ($module in $(Get-ChildItem)) { $module_imp = Import-Clixml -Path C:\Users\Rakhesh\Downloads\Modules\$module Save-Help -DestinationPath C:\Users\Rakhesh\Downloads\Saved -Module $module_imp } |
Copy the downloaded files back to the virtual machine and do something like this:
1 |
update-help -SourcePath c:\Users\rakhesh.RAXNET\Downloads\Saved |
That’s all!