Skip to content

Test ModuleExist

dscbot edited this page Feb 13, 2024 · 1 revision

Test-ModuleExist

SYNOPSIS

Checks if a PowerShell module with a specified name is available in a $env:PSModulePath.

SYNTAX

Default (Default)

Test-ModuleExist [-Name <String>] [-Version <String>] [<CommonParameters>]

Path

Test-ModuleExist [-Name <String>] -Path <String> [-Version <String>] 
 [<CommonParameters>]

Scope

Test-ModuleExist [-Name <String>] -Scope <String> [-Version <String>] 
 [<CommonParameters>]

DESCRIPTION

The Test-ModuleExist function checks if a PowerShell module with the specified name is available in a $env:PSModulePath. It can also filter the modules based on the scope or folder path. Additionally, it can filter the modules based on a specific version.

See also Assert-Module.

EXAMPLES

EXAMPLE 1

Test-ModuleExist -Name 'MyModule' -Scope 'CurrentUser'

Checks if a module named 'MyModule' exists in the current user's module scope.

EXAMPLE 2

Test-ModuleExist -Name 'MyModule' -Path 'C:\Modules'

Checks if a module named 'MyModule' exists in the specified path.

EXAMPLE 3

Test-ModuleExist -Name 'MyModule' -Path 'local/share/powershell/Module'

Checks if a module named 'MyModule' exists in a $env:PSModulePath that matches the specified path. If for example 'MyModule' exist in the path /home/username/.local/share/powershell/Module it returns $true.

EXAMPLE 4

Test-ModuleExist -Name 'MyModule' -Version '1.0.0'

Checks if a module named 'MyModule' with version '1.0.0' exists.

PARAMETERS

-Name

The name of the module to check is available.

Type: String
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-Path

The path where the module should be available. This parameter is used to filter the modules based on the path. The specified path must match (fully or partially) one of the $env:PSModulePath paths.

Type: String
Parameter Sets: Path
Aliases:

Required: True
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-Scope

The scope where the module should be available. This parameter is used to filter the modules based on the scope.

Type: String
Parameter Sets: Scope
Aliases:

Required: True
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-Version

The version of the module. This parameter is used to filter the modules based on a specific version.

Type: String
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

CommonParameters

This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.

INPUTS

OUTPUTS

System.Boolean

NOTES

RELATED LINKS

Clone this wiki locally