When you install modules for multiple versions of a product, you can install multiple modules for the same product, or you can write a single module for the multiple versions. For example, for products that can run multiple versions side by side, you can install modules in different folders similar to how the product is installed. Wherever your modules are installed, you must update your PSModulePath system environment variable to point to the installation location. For more information about this variable, see PSModulePath Environment Variable.
Where to Install Modules
For products that install modules as shared components (modules that are used by multiple components of a product or by multiple versions of a product), install the modules in the Common Files folder along with other shared components. For example, suppose that Fabrikam has a binary module for its product. After you install multiple versions of the product, the value of the PSModulePath variable might resemble the following value:
$Env:PSModulePath = "C:\Users\username\Documents\WindowsPowerShell\Modules;C:\Windows\System32\WindowsPowerShell\v1.0\Modules;C:\Program Files\Common Files\Fabrikam\Modules"
The file structure might resemble the following file structure. Note that the common "Modules" folder contains a subfolder for each module.
C:\ProgramFiles
CommonFiles
Fabrikam
Modules
Fabrikam8
Fabrikam8.psd1 (Manifest file)
FabrikamCmdlets.dll (assembly)
Fabrikam9
Fabrikam9.psd1 (Manifest file)
FabrikamCmdlets.dll (assembly)
For products that do not treat their modules as shared components, or if the modules have the same names, design the modules so that the user can specify the Version parameter when running the Import-Module cmdlet to force a particular module version to be imported. In this case, the value of the PSModulePath variable might resemble the following value:
$Env:PSModulePath = "C:\Users\username\Documents\WindowsPowerShell\Modules;C:\Windows\System32\WindowsPowerShell\v1.0\Modules;C:\Program Files\Fabrikam\Fabrikam8;C:\Program Files\Fabrikam\Fabrikam9"
The file structure might resemble the following file structure. Note that in this case, separate module folders exist for each version of the Fabrikam product so that the PSModulePath variable contains paths to the module folder of each version.
C:\ProgramFiles
Fabrikam
Fabrikam8
FabriKamModule
FabrikamModule.psd1 (Manifest file: ModuleVersion = “8.0”)
FabrikamCmdlets.dll (assembly)
Fabrikam9
FabrikamModule
FabrikamModule.psd1 (Manifest file: ModuleVersion = “9.0”)
FabrikamCmdlets.dll (assembly)
In both of the previous scenarios, the user could have version 8, version 9, or both versions loaded in a Windows PowerShell session by running either or both of the following commands:
Import-Module FabrikamModule –Version8
Import-Module FabrikamModule –Version9
Handling Element Name Conflicts
To handle the conflicts that can occur when modules import multiple elements that have the same name, the Prefix parameter of the Import-Module cmdlet can be used to add version number prefixes to the elements when they are exported. If prefixes are not added, the default behavior is to let the last exported element overwrite the previous element.
Product Version Numbers in Module Names
Version numbers can be added to module names if the module name matches the major version number of a product. For example, Fabrikam8Module and Fabrikam9Module work well for the Fabrikam 8.0 and Fabrikam 9.0 products. However, putting the version in the module name may not be appropriate when only the minor version number of the product changes, such as Fabrikam8.1Module and Fabrikam8.2Module.
See Also