-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAdd-DirToSystemEnv.ps1
45 lines (32 loc) · 1.04 KB
/
Add-DirToSystemEnv.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
<#
.SYNOPSIS
Add path to system environment variables
.EXAMPLE
PS > Add-DirToSystemEnv -PathToAdd "C:\Work\Projects\azure-demo-monitoring-basics\"
add folder to system environment variables
.EXAMPLE
PS > Add-DirToSystemEnv -PathToAdd "C:\Work\Projects\azure-demo-monitoring-basics\" -RerstartCurrentSession
add folder to system environment variables
#>
[CmdletBinding(DefaultParameterSetName = "System")]
param(
[Parameter(HelpMessage = "Provide the path to add to system environment")]
[string]
$PathToAdd,
[switch]$RestartCurrentSession
)
if ($PathToAdd -eq "") {
Write-Verbose "Path to add is not defined, use Get-Location optin."
$PathToAdd = Get-Location
}
Write-Verbose "Path to add: $PathToAdd"
Get-ChildItem -Path $PathToAdd -Recurse -Directory | ForEach-Object {
$path = $_.FullName
Write-Verbose "Path to add: $path"
$env:Path += ";$path"
}
if ($RestartCurrentSession) {
Write-Verbose "Restarting current session."
. $profile
}
Write-Output "Directory added to system environment variables."