Private/Provider/Invoke-ProviderInstall.ps1
|
function Invoke-ProviderInstall { param( [string]$Name, [string]$Version, [string]$Scope = 'CurrentUser', [string]$Repository = 'PSGallery', [switch]$Force ) $provider = Get-ModuleProvider try { Import-ActiveProvider -Provider $provider $installParams = @{ Name = $Name Repository = $Repository Scope = $Scope ErrorAction = 'Stop' } if ($provider -eq 'PSResourceGet') { if ($Version) { $installParams['Version'] = $Version } if ($Force) { $installParams['Reinstall'] = $true } Install-PSResource @installParams } else { $installParams['Force'] = $Force.IsPresent $installParams['AllowClobber'] = $true if ($Version) { $installParams['RequiredVersion'] = $Version } Install-Module @installParams } } catch { throw "Failed to install '$Name': $_" } } |