Skip to content

Commit bc4be12

Browse files
committed
✨ feat: added function for powershell: Add-ToPath
1 parent 785cf2c commit bc4be12

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

dotposh/Modules/Add-ToPath.ps1

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
function Add-ToPath {
2+
param (
3+
[string]$Path
4+
)
5+
$EnvPath = [System.Environment]::GetEnvironmentVariable('path', "User")
6+
if ($EnvPath | Where-Object { $_ -like "*$Path*" } ) {
7+
Write-Host "Path: $Path already added to PATH."
8+
}
9+
else {
10+
[System.Environment]::SetEnvironmentVariable('path', "$Path;" + [System.Environment]::GetEnvironmentVariable('path', "User"), "User")
11+
if ($LASTEXITCODE -eq 0) {
12+
Write-Host "Path: $Path added to PATH successfully."
13+
}
14+
else {
15+
Write-Host "Path: $Path added to PATH failed."
16+
}
17+
}
18+
}

0 commit comments

Comments
 (0)