-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRefresh-Path.ps1
More file actions
56 lines (43 loc) · 1.25 KB
/
Refresh-Path.ps1
File metadata and controls
56 lines (43 loc) · 1.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
<#PSScriptInfo
.VERSION 2023.03.22
.AUTHOR Levente Rog
.COPYRIGHT (c) 2023 Levente Rog
.LICENSEURI https://github.com/levid0s/useful/blob/master/LICENSE.md
.PROJECTURI https://github.com/levid0s/useful/
#>
<#
.SYNOPSIS
Refresh the %PATH% in current shell to whatever is set in the Registry.
Useful when new apps were installed and you don't want to close your shell.
.EXAMPLE
Refresh-Path.ps1
#>
function Get-EnvPathsArr {
[OutputType([String[]])]
Param(
[ValidateSet('User', 'Machine', 'All')]
$Scope = 'All'
)
$Paths = @()
if ( @('Machine', 'All') -icontains $Scope) {
$Paths += `
[Environment]::GetEnvironmentVariable("Path", [EnvironmentVariableTarget]::Machine).Split(';', [System.StringSplitOptions]::RemoveEmptyEntries)
}
if ( @('User', 'All') -icontains $Scope) {
$Paths += `
[Environment]::GetEnvironmentVariable("Path", [EnvironmentVariableTarget]::User).Split(';', [System.StringSplitOptions]::RemoveEmptyEntries)
}
return $Paths
}
###
### Refresh Shell
###
$pathsRegistry = $(Get-EnvPathsArr) -join ';'
if ($pathsRegistry -ne $env:Path) {
Write-Output "Refreshing %PATH% in current shell..."
$env:Path = $(Get-EnvPathsArr) -join ';'
}
else {
Write-Output "%PATH% already up to date."
}
Write-Output ''