-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathInvoke-BootstrapPackageManagement.ps1
30 lines (26 loc) · 1.3 KB
/
Invoke-BootstrapPackageManagement.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
function Invoke-BootstrapPackageManagement {
[CmdletBinding()]
Param()
if ($PSVersionTable.PSVersion.ToString() -match '^5.1') {
$scriptBlock = {
Install-PackageProvider 'NuGet' -Force -MinimumVersion '2.8.5.208' -Scope AllUsers -WarningAction SilentlyContinue | Out-Null
Set-PSRepository -Name 'PSGallery' -InstallationPolicy Trusted
Install-Module -Name 'PackageManagement' -Force -Scope AllUsers -WarningAction SilentlyContinue | Out-Null
Install-Module -Name 'PowerShellGet' -Force -Scope AllUsers -WarningAction SilentlyContinue | Out-Null
}
}
elseif ($IsWindows) {
$scriptBlock = {
Set-PSRepository -Name 'PSGallery' -InstallationPolicy Trusted
Install-Module -Name 'PackageManagement' -Force -Scope AllUsers -WarningAction SilentlyContinue | Out-Null
Install-Module -Name 'PowerShellGet' -Force -Scope AllUsers -WarningAction SilentlyContinue | Out-Null
}
}
else {
Write-Error -Message 'This function requires Windows PowerShell or PowerShell Core on Windows.'
throw
}
Write-Output 'Bootstrapping package management'
Start-Job -ScriptBlock $scriptBlock | Wait-Job | Receive-Job | Out-Null
Write-Output 'Package management boostrapped'
}