Pages

Thursday, 7 October 2021

Remove only path variable through powershell

 $path = [System.Environment]::GetEnvironmentVariable(

    'PATH',
    'User' # For user variable
    #'Machine' for system variable
)
 
$path = ($path.Split(';') | Where-Object { $_ -ne 'var1' }) -join ';'
 
$path = ($path.Split(';') | Where-Object { $_ -ne 'var2' }) -join ';'
# Set it
[System.Environment]::SetEnvironmentVariable(
    'PATH',
    $path,
    'User' # For user variable
    #'Machine' for system variable
)

No comments:

Post a Comment

test

 # Set the file path you want to check $filePath = "C:\Path\To\Your\File.exe" # Check if file exists if (Test-Path $filePath) {   ...

Search This Blog