2021-12-14 04:23:45 +00:00
|
|
|
param(
|
|
|
|
[switch]$IgnoreSystem,
|
|
|
|
[switch]$MissingOnly,
|
|
|
|
[switch]$GenInstallCode,
|
|
|
|
[switch]$UserScope
|
|
|
|
)
|
2021-02-20 00:22:46 +00:00
|
|
|
|
2021-12-14 04:23:45 +00:00
|
|
|
$local:scopeStr = ""
|
|
|
|
if( $UserScope ) { $scopeStr = " -Scope CurrentUser" }
|
2021-02-20 00:22:46 +00:00
|
|
|
$local:currentSys = @('Always') + ([SystemName]::_GetValidValues('',$true,$true));
|
|
|
|
|
2021-03-26 18:10:18 +00:00
|
|
|
$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"
|
2021-10-29 17:31:24 +00:00
|
|
|
, "# Set-PSRepository -Name PSGallery -InstallationPolicy Trusted"
|
2021-03-26 18:10:18 +00:00
|
|
|
, " [Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12"
|
2021-12-14 04:23:45 +00:00
|
|
|
, " Install-PackageProvider -Name NuGet -Force${scopeStr}"
|
2021-03-26 18:10:18 +00:00
|
|
|
, " Remove-Module PowerShellGet"
|
2021-12-14 04:23:45 +00:00
|
|
|
, " Install-Module -Name PowerShellGet -Force${scopeStr}"
|
2021-03-26 18:10:18 +00:00
|
|
|
, " Update-Module -Name PowerShellGet"
|
|
|
|
) -join "`n" )
|
|
|
|
}
|
|
|
|
|
2021-10-29 17:31:24 +00:00
|
|
|
if( $GenInstallCode ) {
|
|
|
|
$MissingOnly = $true
|
|
|
|
"# Set-PSRepository -Name PSGallery -InstallationPolicy Trusted"
|
|
|
|
}
|
2021-02-20 00:22:46 +00:00
|
|
|
[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 }
|
|
|
|
)
|
2021-10-29 17:31:24 +00:00
|
|
|
} | ForEach-Object {
|
|
|
|
if( -not $GenInstallCode ) { return $_ }
|
|
|
|
"Write-Host -ForegroundColor Cyan 'Installing $_...';"
|
2021-12-14 04:23:45 +00:00
|
|
|
"Install-Module $_ -AllowClobber${scopeStr}"
|
2021-02-20 00:22:46 +00:00
|
|
|
}
|
2021-12-14 04:23:45 +00:00
|
|
|
if( $GenInstallCode ) {
|
|
|
|
". Reload-MyScripts"
|
|
|
|
}
|