-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathInstall-Module.ps1
62 lines (51 loc) · 2.26 KB
/
Install-Module.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
param(
[Switch]$Force,
[ValidateSet("CurrentUser","AllUser")]
$Scope = "CurrentUser"
)
$ProfileDir = Split-Path $Profile.CurrentUserAllHosts
mkdir $ProfileDir\Modules -force | convert-path | Push-location
try {
$ErrorActionPreference = "Stop"
if(Test-Path Profile-master){
Write-Error "The Profile-master folder already exists, install cannot continue."
}
if (Test-Path Profile){
Write-Warning "The Profile module already exists, install will overwrite it and put the old one in Profile/old."
Remove-Item Profile/old -Recurse -Force -ErrorAction SilentlyContinue
}
$ProgressPreference = "SilentlyContinue"
Invoke-WebRequest https://github.com/Jaykul/Profile/archive/master.zip -OutFile Profile-master.zip
$ProgressPreference = "Continue"
Expand-Archive Profile-master.zip .
$null = mkdir Profile-master\old
if (Test-Path Profile) {
Move-Item Profile\* Profile-master\old
Remove-Item Profile
}
Rename-Item Profile-master Profile
Remove-Item Profile-master.zip
if (!$Force -and (Test-Path $Profile.CurrentUserAllHosts)) {
Write-Warning "Profile.ps1 already exists. Leaving existing profile in $($Profile.CurrentUserAllHosts)"
} else {
Set-Content $Profile.CurrentUserAllHosts @'
$Actual = @(
"$PSScriptRoot\Modules\Profile\profile.ps1"
"A:\.pscloudshell\PowerShell\Modules\Profile\profile.ps1"
"$Home\Projects\Modules\Profile\profile.ps1"
).Where({Test-Path $_}, 'First', 1)
Write-Host "Actual Profile: $Actual" -ForegroundColor DarkYellow
. $Actual
'@ -Encoding ascii
}
$Gallery = Get-PSRepository PSGallery
Set-PSRepository -Name PSGallery -InstallationPolicy Trusted
$RequiredModules = (Get-Module Profile -ListAvailable).RequiredModules.Name
Write-Host "Installing Required Modules in Scope:$Scope $($RequiredModules -join ', ')"
Find-Module $RequiredModules |
Find-Module -AllowPrerelease |
Install-Module -Scope:$Scope -RequiredVersion { $_.Version } -AllowPrerelease -AllowClobber
Set-PSRepository -Name PSGallery -InstallationPolicy $Gallery.InstallationPolicy
} finally {
Pop-Location
}