-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAddToUserPath.ps1
More file actions
29 lines (22 loc) · 921 Bytes
/
AddToUserPath.ps1
File metadata and controls
29 lines (22 loc) · 921 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
29
# PowerShell 7 Script to Add 'Bin' in User's Home to Environment Variable
param (
[string]$PathToAdd = "$HOME\Bin"
)
function Add-PathToUserProfile {
param (
[string]$Path
)
# Getting the current path environment variable
$currentPath = [Environment]::GetEnvironmentVariable("Path", [EnvironmentVariableTarget]::User)
# Check if the path already exists in the environment variable
if ($currentPath -like "*$Path*") {
Write-Host "Path $Path already exists in user environment variable."
} else {
# Adding the new path
$newPath = $currentPath + ";" + $Path
[Environment]::SetEnvironmentVariable("Path", $newPath, [EnvironmentVariableTarget]::User)
Write-Host "Path $Path added to user environment variable."
}
}
# Call the function with either the default 'Bin' directory or the provided path
Add-PathToUserProfile -Path $PathToAdd