forked from OCram85/PSCredentialStore
Marco Blessing
afab3c870c
## About This pull request reflects all changes done in the `linuxsupport` branch. ## Content - Enable PowerShell 6 Core support - Use PFX Certificate for encryption ( fixes #32 ) - Updates CI / CD pipeline ( fixes #31 ) - uses portable libressl ( fixes #34 ) - adds `-PassThru` switch for returning current `VIServer` session in `Connect-To` ( fixes #34 ) - adds git lfs for embedded libressl files - restructured internal functions into `Private` dir - added certificate related functions - adds travis build pipeline for tests
80 lines
2.0 KiB
PowerShell
80 lines
2.0 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
|
|
|
|
.NOTES
|
|
```
|
|
File Name : Test-Module.ps1
|
|
Author : Marco Blessing - marco.blessing@googlemail.com
|
|
Requires :
|
|
```
|
|
|
|
.LINK
|
|
https://github.com/OCram85/PSCredentialStore
|
|
#>
|
|
[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 {}
|
|
}
|