PSCredentialStore/src/Private/Test-Module.ps1
Marco Blessing 7708df9b66
Update pwsh style to latest community standards (#52)
* update pwsh style in store files

* update pwsh style in item files

* update pwsh style in connection files

* update pwsh style in certificate files

* update pwsh style in private files

* update pwsh style in drone helper

* update meta

* fix pwsh style

* fix output type

* fix typo in OutputType

* update appveyor build mode

* debugging build mode

* wip

* test windows pipeline

* fix typo

* simplify drone setup

* update readme

* remove deprecated cicd setup

* update pwsh style
2022-06-28 08:56:33 +02:00

72 lines
1.8 KiB
PowerShell

function Test-Module {
<#
.SYNOPSIS
Tests if the given module exists on the local system.
.DESCRIPTION
Tests if the given module is installed on the local system. It returns a bool value as result.
.PARAMETER Name
Define a item name you need to test
.PARAMETER Type
Define the dependency type. This could be a Module or PSnapin.
.PARAMETER MessagePattern
You an optionally adjust the message pattern for the error message itself.
The available placeholders are:
- {0} : Type
- {1} : Name
.PARAMETER StopIfFails
This switch forces the entire script to stop if the given dependency object fails.
.INPUTS
[None]
.OUTPUTS
[Bool]
.EXAMPLE
.\Test-Dependency -Name 'VMware.PowerCLI' -Type 'Module'
.EXAMPLE
.\Test-Dependency -Name 'VMware.PowerCLI' -Type 'Module' -StopIfFails
#>
[OutputType([bool])]
[CmdletBinding()]
param (
[Parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[string]$Name,
[Parameter(Mandatory = $false)]
[ValidateNotNullOrEmpty()]
[string]$MessagePattern = @"
Could not find the required {0} called {1}. Please install the required {0} to run this function!
"@,
[Parameter(Mandatory = $false)]
[switch]$StopIfFails
)
begin {}
process {
$Message = $MessagePattern -f $Type, $Name
Write-Debug $Message
if (Get-Module -Name $Name -ListAvailable) {
return $true
}
else {
if ($StopIfFails) {
Write-Error -Message $Message -ErrorAction Stop -Category NotInstalled
}
return $false
}
}
end {}
}