46 lines
1.8 KiB
PowerShell
46 lines
1.8 KiB
PowerShell
param([switch]$IgnoreSystem,[switch]$MissingOnly,[switch]$GenInstallCode)
|
|
|
|
$local:currentSys = @('Always') + ([SystemName]::_GetValidValues('',$true,$true));
|
|
|
|
$local:oldPSGet = Get-Module PowerShellGet -ListAvailable -ErrorAction SilentlyContinue |
|
|
Sort-Object -Property Version -Descending |
|
|
Select-Object -First 1 |
|
|
Where-Object { $_.Version.Major -eq 1 }
|
|
if( $local:oldPSGet ) {
|
|
Write-Warning $(@(
|
|
"PowerShellGet is an old version ($($oldPSGet.Version)), the following code should upgrade it"
|
|
, "# Set-PSRepository -Name PSGallery -InstallationPolicy Trusted"
|
|
, " [Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12"
|
|
, " Install-PackageProvider -Name NuGet -Force"
|
|
, " Remove-Module PowerShellGet"
|
|
, " Install-Module -Name PowerShellGet -Force"
|
|
, " Update-Module -Name PowerShellGet"
|
|
) -join "`n" )
|
|
}
|
|
|
|
if( $GenInstallCode ) {
|
|
$MissingOnly = $true
|
|
"# Set-PSRepository -Name PSGallery -InstallationPolicy Trusted"
|
|
}
|
|
[MyConfig]::GetConfigPaths('mymodules',$false) |
|
|
ForEach-Object {
|
|
$local:modules = $( Get-Content $_ | ConvertFrom-Json );
|
|
$modules |
|
|
Get-Member -MemberType NoteProperty | Select-Object -ExpandProperty Name |
|
|
Where-Object {
|
|
$IgnoreSystem -or ( $_ -in $currentSys )
|
|
} |
|
|
ForEach-Object { $modules."$_" }
|
|
} |
|
|
Where-Object {
|
|
-not $MissingOnly -or
|
|
$( try {
|
|
-not (Get-Module -ListAvailable $_ -ErrorAction stop)
|
|
} catch { $true }
|
|
)
|
|
} | ForEach-Object {
|
|
if( -not $GenInstallCode ) { return $_ }
|
|
"Write-Host -ForegroundColor Cyan 'Installing $_...';"
|
|
"Install-Module $_ -AllowClobber"
|
|
}
|