Ensure PowerShell Module
  • 14 May 2021
  • 1 Minute to read
  • Dark
    Light
  • PDF

Ensure PowerShell Module

  • Dark
    Light
  • PDF

Article Summary

This is generated from the built in components of Otter 3.0.0, and may be different than what you have installed (especially if you have extensions); go to [User Icon] -> Documentation within your BuildMaster instance to see exactly what operations are available.

Ensure PowerShell Module

Ensures that the specified PowerShell module is installed.

Script usage:

Ensure-PsModule(
	Module: <text>,
	[Version: <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>]
);

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
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.
Repository Name
text
Repository
Scope
text
Scope
Typically "Local" or "Global"
Exists
true/false
Exists
Allow Clobber
true/false
AllowClobber
Allow Prerelease
true/false
AllowPrerelease
Accept License
true/false
AcceptLicense
For PowerShell Core only!
All Versions
true/false
AllVersions
Parameters
%(key1: value1, ...)
Parameters
Additional parameters to pass to Install-Module. Example: %(DestinationPath: C:\hdars\1000.txt, Contents: test file ensured)
Verbose
true/false
Verbose
Debug Logging
true/false
DebugLogging

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 file on the server
Ensure-DscResource(
  Name: File,
  ConfigurationKey: DestinationPath,
  Properties: %(
    DestinationPath: C:\hdars\1000.txt,
    Contents: test file ensured)
);

# runs a custom resource
Ensure-DscResource(
  Name: cHdars,
  Module: cHdarsResource,
  ConfigurationKey: LocalServer,
  Properties: %(
    MaximumSessionLength: 1000,
    PortsToListen: @(3322,4431,1123),
    Enabled: true)
);

Was this article helpful?

What's Next