-
Notifications
You must be signed in to change notification settings - Fork 26
/
Import-Store.ps1
68 lines (55 loc) · 2 KB
/
Import-Store.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
63
64
65
66
67
68
function Import-Store
{
[cmdletBinding()]
Param(
# What name would you prefer the drive to be mapped under.
[string]$Store = "ps"
, # Store Root Path
[string]$StoreRoot = (Join-Path $HOME 'ps')
# Verbose output with ". $profile.currentUserAllHosts -Verbose" in a session to view extra information
)
$Verbose = $VerbosePreference
Write-Verbose "Map folder: $StoreRoot"
Write-Verbose "To drive : $Store"
# ---------- Create the store drive ----------
$v = measure-command {
try
{
Get-PSDrive $Store -ErrorAction stop -PSProvider FileSystem
}
catch [System.Exception]
{
Write-Verbose "Map the folder '$StoreRoot' as drive '$store'"
$Drive = @{
Root = $StoreRoot
Description = "Powershell script and module store"
Name = $Store
PSProvider = "FileSystem"
Scope = "Global"
}
New-PSDrive @Drive
}
catch
{
Write-Verbose 'No Fault'
}
}
Write-Verbose "$('{0:N6}' -f $v.TotalSeconds) seconds - Ensured the store existed"
# ---------- Add store to module path ----------
$v = measure-command {
Write-Verbose "Path before testing for the store:"
$env:PSModulePath.split(';') | % {Write-Verbose " $PSItem"}
# Check to see if the above added drive is in the module path. If not, add it.
if($env:PSModulePath.Contains("$Store`:"))
{
Write-Verbose "Store exists"
} else {
Write-Verbose "! Store not found"
Write-Verbose "Add to PSModulePath the store: $Store"
$env:PSModulePath = $env:PSModulePath.Insert(0, "$Store`:\;")
Write-Verbose "Path after adding;"
$env:PSModulePath.split(';') | % {Write-Verbose " $PSItem"}
}
}
Write-Verbose "$($v.TotalSeconds) seconds - add store to path"
}