-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathGenerate-PSDrives.ps1
More file actions
28 lines (19 loc) · 946 Bytes
/
Generate-PSDrives.ps1
File metadata and controls
28 lines (19 loc) · 946 Bytes
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
$file = Join-Path $env:UserProfile psdrives.txt
$reg = [regex] '^(\S+)\s+(\S.*)'
$current = (gl).Path.Split(':') | select-object -First 1
foreach($linha in & {if(Test-Path($file)) { gc $file; }; "psu $PSScriptRoot"; } ) {
$m = $reg.Match($linha)
if($m.Success) {
$prefix = $m.Groups[1].Value.Trim();
$path = $m.Groups[2].Value.Trim();
Write-Verbose "[PSUtils] Mapping ${prefix}: PSDrive to $path"
if($prefix.ToLower() -ne $current.ToLower()) {
"get-psdrive $prefix -ErrorAction SilentlyContinue | Remove-PsDrive"
"New-PSDrive -PSProvider FileSystem -Scope Global -Name $prefix -Root '$path' | out-null"
}
"function Set-Location_$prefix { cd ${prefix}: }"
"Set-Alias '${prefix}:' 'Set-Location_$prefix'"
"Export-ModuleMember -function Set-Location_$prefix"
"Export-ModuleMember -alias ${prefix}:"
}
}