-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDelete-Modules.ps1
More file actions
68 lines (56 loc) · 2.25 KB
/
Copy pathDelete-Modules.ps1
File metadata and controls
68 lines (56 loc) · 2.25 KB
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
63
64
65
66
67
68
<#
.SYNOPSIS
Resets LibreDevOpsHelpers and reinstalls it from the PowerShell Gallery.
.DESCRIPTION
Uninstalls all installed versions of LibreDevOpsHelpers, removes any leftover module folders
from PSModulePath, reinstalls the latest version from the PowerShell Gallery, patches the
nested module filename casing for case-sensitive file systems, then imports and verifies it.
#>
Set-StrictMode -Version Latest
Write-Host 'Uninstalling existing LibreDevOpsHelpers versions...'
try {
Uninstall-Module LibreDevOpsHelpers -AllVersions -Force -ErrorAction Stop
Write-Host ' Uninstall-Module completed.'
}
catch {
Write-Host ' (No existing PSGallery versions found.)'
}
Write-Host 'Removing leftover module folders from PSModulePath...'
$env:PSModulePath -split [IO.Path]::PathSeparator |
ForEach-Object {
$dir = Join-Path $_ 'LibreDevOpsHelpers'
if (Test-Path $dir) {
Write-Host " Deleting $dir"
Remove-Item $dir -Recurse -Force
}
}
Write-Host 'Installing LibreDevOpsHelpers from PSGallery...'
Install-Module LibreDevOpsHelpers -Scope CurrentUser -Force -AllowClobber -ErrorAction Stop
Write-Host 'Patching installed module for case-sensitive file systems...'
$mod = Get-Module -ListAvailable -Name LibreDevOpsHelpers |
Sort-Object Version -Descending | Select-Object -First 1
if (-not $mod) {
Write-Error 'Could not find the installed module.'
exit 1
}
$base = $mod.ModuleBase
Get-ChildItem -Path $base -Recurse -Filter 'LibreDevopsHelpers.*.psm1' |
ForEach-Object {
$newName = $_.Name -replace '^LibreDevopsHelpers', 'LibreDevOpsHelpers'
Write-Host " Renaming $($_.FullName) to $newName"
Rename-Item $_.FullName -NewName $newName -Force
}
$psd1 = Join-Path $base 'LibreDevOpsHelpers.psd1'
Write-Host " Patching manifest at $psd1"
(Get-Content $psd1) -replace 'LibreDevopsHelpers\.', 'LibreDevOpsHelpers.' | Set-Content $psd1
Write-Host 'Importing LibreDevOpsHelpers...'
Import-Module LibreDevOpsHelpers -Force
Write-Host 'Verifying Write-LdoLog is available...'
if (Get-Command Write-LdoLog -ErrorAction SilentlyContinue) {
Write-Host 'LibreDevOpsHelpers loaded successfully.'
exit 0
}
else {
Write-Error 'Failed to load LibreDevOpsHelpers.'
exit 1
}