Internet Explorer is no longer supported. Many things will still work, but your experience will be degraded and some things won't function. Please use a modern browser such as Edge, Chrome, or Firefox.

Ensure PowerShell Module

Ensures that the specified PowerShell module is installed.

Script usage:

Ensure-PsModule(
	Module: <text>,
	[Version: <text>],
	[MinimumVersion: <text>],
	[Force: <true/false>],
	[Repository: <text>],
	[Scope: <text>],
	[Exists: <true/false>],
	[AllowClobber: <true/false>],
	[AllowPrerelease: <true/false>],
	[AcceptLicense: <true/false>],
	[AllVersions: <true/false>],
	[Parameters: <%(key1: value1, ...)>],
	[Verbose: <true/false>],
	[DebugLogging: <true/false>],
	[PreferWindowsPowerShell: <text>]
);

This operation may be prefixed with PowerShell::, although this is a built-in namespace and isn't really necessary.

Arguments:

NameFormatScript UsageUsage Notes
Module
text
Module
This argument is required.
Version
text
Version
Minimum Version
text
MinimumVersion
Force
true/false
Force
Use this to force installation to bypass the Untrusted Repository error or to force this version to install side-by-side with other versions that already exist. Default value is "False".
Repository Name
text
Repository
Scope
text
Scope
Typically "Local" or "Global".
Exists
true/false
Exists
Default value is "True".
Allow Clobber
true/false
AllowClobber
Default value is "False".
Allow Prerelease
true/false
AllowPrerelease
Default value is "False".
Accept License
true/false
AcceptLicense
For PowerShell Core only!. Default value is "False".
All Versions
true/false
AllVersions
Default value is "False".
Parameters
%(key1: value1, ...)
Parameters
Additional parameters to pass to Install-Module. Example: %(DestinationPath: C:\hdars\1000.txt, Contents: test file ensured). Value note: "%(...)".
Verbose
true/false
Verbose
Default value is "False".
Debug Logging
true/false
DebugLogging
Default value is "False".
Prefer Windows PowerShell
text
PreferWindowsPowerShell
When true, the script will be run using Windows PowerShell 5.1 where available. When false or on Linux (or on Windows systems without PowerShell 5.1 installed), the script will be run using PowerShell Core instead. Default value is "$PreferWindowsPowerShell".

Note: An argument may be explicitly converted to an integral type by prefixing the value with [type::<typeName>], where <typeName> is one of: int, uint, long, ulong, double, decimal. Normally this conversion is performed automatically and this is not necessary.

Example:


# ensures the existence of a module on the server
Ensure-PsModule
(
    Module: PackageManagement,
    MinimumVersion: 1.4.6,
    Repository: internal-powershell,
    Exists: true
);

# ensures the existence of a specific version of a module on the server
Ensure-PsModule
(
    Module: PackageManagement,
    Version: 1.4.6,
    Repository: internal-powershell,
    Force: true,
    Exists: true
);