PowerShell_Scripts/base/profile.d/EnsureJoinString.ps1
Gal Szkolnik 22aa3ba435 Improve performance of Package identification
Using -ListAvailable with Get-Command to ensure no module loading is
    attampeted while querying loaded commands.
    This improved performance when certain modules have not been
    loaded yet
2021-04-27 16:04:12 +00:00

12 lines
No EOL
602 B
PowerShell

if( -not (Get-Command -ListImported Join-String -ErrorAction SilentlyContinue) ) {
if( -not (Get-Module -ListAvailable -Name "string") ) {
Write-Warning 'Join-String Command is missing, attempting to install stirng module'
$local:moduleScope = "CurrentUser"
if( Test-IsAdmin ) { $moduleScope = "AllUsers" }
Install-Module -Name "string" -Scope $moduleScope -AllowClobber -ErrorAction SilentlyContinue
}
if( -not (Get-Module -ListAvailable -Name "string") ) {
Write-Error "Failed to locate/install the module 'string'"
}
Import-Module -Name "string" -Cmdlet "Join-String"
}