-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInstall.ps1
More file actions
55 lines (47 loc) · 1.77 KB
/
Copy pathInstall.ps1
File metadata and controls
55 lines (47 loc) · 1.77 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
#Requires -Version 5.1
# Get module version from the manifest
$manifestPath = Join-Path $PSScriptRoot "DriveTools.psd1"
if (-not (Test-Path $manifestPath)) {
Write-Error "Could not find manifest at $manifestPath"
return
}
$manifest = Import-PowerShellDataFile $manifestPath
$version = $manifest.ModuleVersion
# Determine user modules directory depending on PowerShell engine
if ($PSEdition -eq 'Core') {
$moduleRoot = "$Home\Documents\PowerShell\Modules"
} else {
$moduleRoot = "$Home\Documents\WindowsPowerShell\Modules"
}
$destPath = Join-Path $moduleRoot "DriveTools\$version"
Write-Host "Installing DriveTools v$version to $destPath..." -ForegroundColor Cyan
# Create destination folder
if (-not (Test-Path $destPath)) {
New-Item -ItemType Directory -Path $destPath -Force | Out-Null
}
# Copy files
$itemsToCopy = @(
"DriveTools.psd1"
"DriveTools.psm1"
"DriveTools.GUI.ps1"
"public"
"src"
"lib"
)
foreach ($item in $itemsToCopy) {
$srcPath = Join-Path $PSScriptRoot $item
if (Test-Path $srcPath) {
Copy-Item -Path $srcPath -Destination $destPath -Recurse -Force
}
}
# Clean up any stale/mismatched version subfolders under DriveTools to avoid version mismatch errors
$parentDir = Join-Path $moduleRoot "DriveTools"
if (Test-Path $parentDir) {
Get-ChildItem -Path $parentDir -Directory | Where-Object { $_.Name -match '^\d+(\.\d+)*$' -and $_.Name -ne $version } | ForEach-Object {
Write-Host "Cleaning up old/mismatched version folder: $($_.FullName)" -ForegroundColor Yellow
Remove-Item -Path $_.FullName -Recurse -Force -ErrorAction SilentlyContinue
}
}
# Import module to verify and load
Import-Module DriveTools -Force
Write-Host "DriveTools v$version installed and imported successfully!" -ForegroundColor Green