File tree Expand file tree Collapse file tree 4 files changed +90
-25
lines changed Expand file tree Collapse file tree 4 files changed +90
-25
lines changed Original file line number Diff line number Diff line change
1
+ param (
2
+ [Parameter (Mandatory = $TRUE )]
3
+ [String ] $PathToModuleFiles ,
4
+ [Parameter (Mandatory = $TRUE )]
5
+ [String ] $ModuleName
6
+ )
7
+
8
+ if (! (Test-Path - PathType Container $PathToModuleFiles )) {
9
+ Write-Error " $PathToModuleFiles not found or is not a directory. Nothing to install."
10
+ exit
11
+ }
12
+
13
+ $moduleRoot = " $ ( $env: CommonProgramW6432 ) \Modules\"
14
+ $dest = " $moduleRoot \$ModuleName \"
15
+
16
+ if (! (Test-Path $moduleRoot )) {
17
+ New-Item - ItemType directory $moduleRoot | out-null
18
+ }
19
+
20
+ Write-Host - NoNewLine " Copying $ModuleName module to $moduleRoot ... "
21
+
22
+ Copy-Item - Force - Recurse $PathToModuleFiles $dest
23
+
24
+ Write-Host - ForegroundColor Green " done"
25
+
26
+ # Update PSModulePath if it needs it
27
+ $path = [Environment ]::GetEnvironmentVariable(" PSModulePath" )
28
+
29
+ $pathContainsRoot = 0 -ne ($path.Split (' ;' ) | ? { Test-Path $_ } | ? { (Resolve-Path $_ ).Path -eq (Resolve-Path $moduleRoot ).Path}).count
30
+
31
+ if (-Not $pathContainsRoot ) {
32
+
33
+ Write-Host - NoNewLine " Adding $moduleRoot to `$ env:PSModulePath... "
34
+
35
+ $path += " ;$moduleRoot "
36
+ [Environment ]::SetEnvironmentVariable(" PSModulePath" , $path , " Machine" )
37
+
38
+ Write-Host - ForegroundColor Green " done"
39
+ }
40
+
41
+ Write-Host " Installation complete."
Original file line number Diff line number Diff line change
1
+ param (
2
+ [Parameter (Mandatory = $TRUE )]
3
+ [String ] $ModuleName
4
+ )
5
+
6
+ $moduleRoot = " $ ( $env: CommonProgramW6432 ) \Modules\"
7
+ $dir = " $moduleRoot \$ModuleName \"
8
+
9
+ if (Test-Path $dir ) {
10
+ Write-Host - NoNewLine " Removing $ModuleName module from $moduleRoot ... "
11
+
12
+ Remove-Item - Recurse - Force $dir
13
+
14
+ Write-Host - ForegroundColor Green " done"
15
+ }
16
+
17
+ if (Test-Path $moduleRoot ) {
18
+ if (! (Get-ChildItem - Recurse - Force $moduleRoot )) {
19
+ Write-Host " Module directory empty."
20
+
21
+ Write-Host - NoNewLine " Removing module directory from `$ env:PSModulePath... "
22
+
23
+ $path = [Environment ]::GetEnvironmentVariable(" PSModulePath" )
24
+
25
+ # Remove match paths but be careful about handling paths that don't
26
+ # exist. We don't want to accidentally remove a path that we didn't
27
+ # add.
28
+ $cleanedPath = $path.Split (' ;' ) |
29
+ Where-Object {
30
+ (-Not (Test-Path $_ )) -or
31
+ ((Resolve-Path $_ ).Path -ne (Resolve-Path $moduleRoot ).Path) } |
32
+ Select-Object - Unique
33
+ $cleanedPath = $cleanedPath -Join ' ;'
34
+
35
+ [Environment ]::SetEnvironmentVariable(" PSModulePath" , $cleanedPath , " Machine" )
36
+
37
+ Write-Host - ForegroundColor Green " done"
38
+
39
+
40
+ Write-Host - NoNewLine " Removing empty module directory... "
41
+ Remove-Item $moduleRoot
42
+ Write-Host - ForegroundColor Green " done"
43
+
44
+ }
45
+
46
+ Write-Host " Removal complete."
47
+ }
Original file line number Diff line number Diff line change @@ -2,20 +2,9 @@ $packageName = "PSReadLine"
2
2
3
3
try {
4
4
$source = Resolve-Path ($PSScriptRoot + " \..\$packageName \" )
5
- $dest64 = " C:\Windows\system32\WindowsPowerShell\v1.0\Modules\"
6
- $dest32 = " C:\Windows\sysWOW64\WindowsPowerShell\v1.0\Modules\"
7
5
8
- $command = " "
6
+ Start-ChocolateyProcessAsAdmin " $PSScriptRoot \Install-Module.ps1 ' $source ' ' $packageName ' "
9
7
10
- if (Test-Path - PathType Container $dest64 ) {
11
- $command = $command + " Copy-Item -Force -Recurse `' $source `' `' $dest64 `' ;"
12
- }
13
-
14
- if (Test-Path - PathType Container $dest32 ) {
15
- $command = $command + " Copy-Item -Force -Recurse `' $source `' `' $dest32 `' "
16
- }
17
-
18
- Start-ChocolateyProcessAsAdmin $command
19
8
20
9
Write-ChocolateySuccess $packageName
21
10
} catch {
Original file line number Diff line number Diff line change 1
1
$packageName = " PSReadLine"
2
2
3
3
try {
4
- $dir64 = " C:\Windows\system32\WindowsPowerShell\v1.0\Modules\$packageName \"
5
- $dir32 = " C:\Windows\sysWOW64\WindowsPowerShell\v1.0\Modules\$packageName \"
6
4
7
- $command = " "
8
-
9
- if (Test-Path - PathType Container $dir64 ) {
10
- $command = $command + " Remove-Item -Recurse -Force `' $dir64 `' ;"
11
- }
12
-
13
- if (Test-Path - PathType Container $dir32 ) {
14
- $command = $command + " Remove-Item -Recurse -Force `' $dir32 `' "
15
- }
16
-
17
- Start-ChocolateyProcessAsAdmin $command
5
+ Start-ChocolateyProcessAsAdmin " $PSScriptRoot \Remove-Module.ps1 '$packageName '"
18
6
19
7
Write-ChocolateySuccess $packageName
20
8
} catch {
You can’t perform that action at this time.
0 commit comments