36 lines
945 B
PowerShell
36 lines
945 B
PowerShell
|
function Use-Module {
|
|||
|
<#
|
|||
|
.SYNOPSIS
|
|||
|
Load a module only once.
|
|||
|
#>
|
|||
|
[CmdletBinding()]
|
|||
|
Param(
|
|||
|
[Parameter(Mandatory=$true)]
|
|||
|
[Alias("ModuleName")]
|
|||
|
[string]$Name
|
|||
|
)
|
|||
|
process {
|
|||
|
$logLead = (Get-LogLeadName);
|
|||
|
|
|||
|
if (!$Name) { throw "Loading of a module requires a name"; }
|
|||
|
|
|||
|
Write-Verbose "$logLead : Attempting to load module $Name";
|
|||
|
|
|||
|
try {
|
|||
|
if (!(Get-Module $Name)) {
|
|||
|
Import-Module $Name -Global -NoClobber -WarningAction SilentlyContinue;
|
|||
|
}
|
|||
|
} catch {
|
|||
|
Write-Verbose "Could not load the module with the safe option of Get-Module so force loading it";
|
|||
|
try {
|
|||
|
Import-Module $Name -Global -NoClobber -WarningAction SilentlyContinue;
|
|||
|
} catch {
|
|||
|
Write-Verbose "Could not install the module $name -- does it exist on this environment?";
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
Write-Verbose "$logLead : Done"
|
|||
|
}
|
|||
|
}
|
|||
|
|