-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPSLoader.ps1
More file actions
74 lines (64 loc) · 1.99 KB
/
Copy pathPSLoader.ps1
File metadata and controls
74 lines (64 loc) · 1.99 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
69
70
71
72
73
74
# user variables
$newModuleLocation = $PSScriptRoot+"\Modules"
# function(s)
function Load-Local {
param (
[Parameter(Mandatory)]
[string]$moduleName,
[string]$moduleVersion
)
if($moduleVersion)
{
if(Test-Path -Path "$($newModuleLocation)\$($moduleName)")
{
Write-Output "$($moduleName) (v$($moduleVersion)) already installed"
}
else {
Find-Module -Name "$($moduleName)" -RequiredVersion $moduleVersion | Save-Module -Path $newModuleLocation -Force
Write-Output "$($moduleName) (v$($moduleVersion)) installed"
}
}
else
{
if(Test-Path -Path "$($newModuleLocation)\$($moduleName)")
{
Write-Output "$($moduleName) already installed"
}
else {
Find-Module -Name "$($moduleName)" | Save-Module -Path $newModuleLocation -Force
Write-Output "$($moduleName) installed"
}
}
}
function Remove-Local {
param ([Parameter(Mandatory)][string]$moduleName)
$directories = (Get-ChildItem -Path $newModuleLocation -Filter "*$($moduleName)*" -Directory)
if($directories.Count -le 0) {
Write-Warning "no modules match input string ""$($moduleName)"""
}
foreach($dir in $directories) {
Remove-Item -Path $dir.FullName -Recurse -Force
Write-Output "Removed $($dir.Name)..."
}
}
#working code
$moduleArray = (Get-Content -Path "$($PSScriptRoot)\modules.txt").Split([System.Environment]::NewLine)
$env:PSModulePath += ";$($newModuleLocation)"
Set-PSRepository -Name "PSGallery" -InstallationPolicy Trusted
Write-Output "Verifying Requisite Modules..."
foreach($module in $moduleArray)
{
$splitvar = $module.Split("|")
if($splitvar[1])
{
Load-Local -moduleName "$($splitvar[0].Trim())" -moduleVersion $splitvar[1].Trim()
}
else {
Load-Local -moduleName "$($module)"
}
}
# change directory (if invoked)
if($args[0])
{
Set-Location "$($args[0])"
}