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

User based detection

function getloggedindetails () {     ##Find logged in username     $user = Get-WmiObject Win32_Process - Filter "Name='explorer...

Search This Blog