7

Summary

What's the difference between the PowerShell Module Manifest values PowerShellVersion and PowerShellHostVersion?

Long Version

When creating a new module manifest there are settings for both the minimum version of PowerShell required by this module, and also the minimum version of the PowerShell Host required. i.e.

New-ModuleManifest -Path '.\MyModule.psd1' -PowerShellVersion '5.0' -PowerShellHostVersion '2.0'

PowerShellVersion relates to $PSVersionTable.PSVersion.Major (NB: Relates to the major version since valid values all have 0 set for their minor version / no build or revision numbers).

PowerShellHostVersion is the one I'm not clear on. My belief is that this relates to $Host.Version (i.e. with PowerShellHostName relating to $Host.Name). However, in my experience both ISE (Windows PowerShell ISE Host) and ConsoleHost have their version numbers inline with the PS version; so it seems odd to require that these be out of sync with the PS version as implied in the example. My hope is these are rarely used parameters for rare use cases; but I want to ensure I've understood correctly what these are for, and if there is a common scenario where they're applicable.

The example values in MSDN's documentation differ (i.e. PowershellVersion is given 5.0, whilst PowershellHostVersion gets 2.0)

The Official Documentation just gives a circular description (i.e. adds no more information than the parameter name itself implies).

JohnLBevan
  • 22,735
  • 13
  • 96
  • 178
  • 2
    As of PowerShell 5.1, PowerShell remote host have version 1.0. – user4003407 Nov 08 '17 at 16:05
  • 1
    Regarding @PetSerAI's comment: reproduced by running: `Enter-PSSession -ComputerName .` `$Host.Version`. Host name is `ServerRemoteHost`. `$PSVersionTable` still gives `5.1.14409.1012`, as would be expected. – JohnLBevan Nov 08 '17 at 16:27
  • Run `findstr /I /S /R "Host.*Version Host.*Name" *.psd1` (from an elevated command prompt) in both `pushd "%psmodulepath%"` and `for /F "delims=" %G in ( 'where powershell.exe' ) do pushd "%~dpG"` folders. I can't find any useful `PowerShellHostVersion` appearance. So, **why** do you want to set it up in your module? – JosefZ Nov 08 '17 at 17:42
  • @JosefZ: Thanks for investigating; nice to know it's not used elsewhere. I don't want to use it; just to understand it so that I'd know when to use it / what the possibilities are. – JohnLBevan Nov 08 '17 at 18:14
  • 2
    Found `PowerShellHostVersion = '1.2'` in **NuGet** module (Micosoft Visual Studio) and in `VS.psd1` (under `Microsoft Web Tools`) along with `PowerShellHostName = 'Package Manager Host'` in both cases. HTH. – JosefZ Nov 08 '17 at 20:45

1 Answers1

0

My belief is that this relates to $Host.Version

Your belief is correct. Tested this by amending the manifest produced to set the value of PowerShellHostVersion to 6.0. When importing, get the error:

Import-Module : The current Windows PowerShell host is: 'ConsoleHost' (version
5.1.15063.674). The module 'C:\MyModule.psd1' requires a minimum Windows PowerShell
host version of '6.0' to run.
At line:1 char:1
+ Import-Module .\MyModule.psd1
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ResourceUnavailable: (C:\MyModule.psd1:String) [Import-M
   odule], InvalidOperationException
    + FullyQualifiedErrorId : Modules_InsufficientPowerShellHostVersion,Microsoft.PowerShel
   l.Commands.ImportModuleCommand

Version related to $Host.Version, and name relates to $Host.Name

PS C:\> $Host.Version

Major  Minor  Build  Revision
-----  -----  -----  --------
5      1      15063  674

This Shavy Levy blog post and the linked PowerShell Team follow up from 2010 give an interesting history. On my machine I get the same output for $Host.Version from Console and ISE hosts.
No clue what version Power GUI and other mentioned hosts use.

G42
  • 9,791
  • 2
  • 19
  • 34