-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadd-php-path.ps1
More file actions
48 lines (38 loc) · 1.29 KB
/
Copy pathadd-php-path.ps1
File metadata and controls
48 lines (38 loc) · 1.29 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
# add-path.ps1
Write-Host "========================================" -ForegroundColor Cyan
Write-Host " Add Folder to Windows PATH " -ForegroundColor Cyan
Write-Host "========================================" -ForegroundColor Cyan
Write-Host ""
# User se folder path lena
$folderPath = Read-Host "Enter the folder path to add to PATH"
# Example
# C:\scripts\php
# Check folder exist karta hai ya nahi
if (-not (Test-Path $folderPath -PathType Container)) {
Write-Host ""
Write-Host "ERROR: Folder does not exist!" -ForegroundColor Red
Write-Host "You entered: $folderPath"
exit
}
# Current Machine PATH
$currentPath = [Environment]::GetEnvironmentVariable("Path", "Machine")
# Check agar already PATH mein hai
$pathEntries = $currentPath -split ";"
if ($pathEntries -contains $folderPath) {
Write-Host ""
Write-Host "This folder is already in Machine PATH." -ForegroundColor Yellow
}
else {
# PATH mein folder add karna
$newPath = $currentPath.TrimEnd(";") + ";" + $folderPath
[Environment]::SetEnvironmentVariable(
"Path",
$newPath,
"Machine"
)
Write-Host ""
Write-Host "SUCCESS!" -ForegroundColor Green
Write-Host "$folderPath has been added to Machine PATH."
}
Write-Host ""
Write-Host "Done." -ForegroundColor Cyan