Skip to content

Remove-EnvironmentPath

SYNOPSIS

Remove a path from the PATH environment variable.

SYNTAX

Remove-EnvironmentPath [[-Scope] <String>] [-ProgressAction <ActionPreference>] [-WhatIf] [-Confirm]
 [<CommonParameters>]

DESCRIPTION

Remove a path from the PATH environment variable. This command will normalize the path separators.

EXAMPLES

EXAMPLE 1

Remove-EnvironmentPath -Scope CurrentUser -Path 'C:\Program Files\Git\cmd'

Remove the path 'C:\Program Files\Git\cmd' from the PATH environment variable for the current user.

EXAMPLE 2

Remove-EnvironmentPath -Scope AllUsers -Path 'C:\Program Files\Git\cmd'

Remove the path 'C:\Program Files\Git\cmd' from the PATH environment variable for all users.

EXAMPLE 3

Remove-EnvironmentPath -Scope CurrentUser -Path 'C:\Program Files\Git\cmd', 'C:\Program Files\Git\bin'

Remove the paths 'C:\Program Files\Git\cmd' and 'C:\Program Files\Git\bin' from the PATH environment variable for the current user.

EXAMPLE 4

'C:\Program Files\Git\cmd', 'C:\Program Files\Git\bin' | Remove-EnvironmentPath -Scope CurrentUser

Remove the paths 'C:\Program Files\Git\cmd' and 'C:\Program Files\Git\bin' from the PATH environment variable for the current user.

EXAMPLE 5

(Get-EnvironmentPath -Scope AllUsers -AsArray) | where {$_ -like "$env:USERPROFILE*"} | Remove-EnvironmentPath -Scope AllUsers

Remove all paths from the PATH environment variable for all users that start with the current user's profile path.

EXAMPLE 6

(Get-EnvironmentPath -Scope CurrentUser -AsArray) |
    where {$_ -like "$env:windir*" -or $_ -like "$env:ProgramFiles*" -or $_ -like "${env:ProgramFiles(x86)}*"} |
    Remove-EnvironmentPath -Scope CurrentUser

Remove all paths from the PATH environment variable for the current user that start with the Windows directory, Program Files directory or Program Files (x86) directory.

PARAMETERS

-Scope

The scope of the environment variable.

Type: String
Parameter Sets: (All)
Aliases:

Required: False
Position: 1
Default value: CurrentUser
Accept pipeline input: False
Accept wildcard characters: False

-WhatIf

Shows what would happen if the cmdlet runs. The cmdlet is not run.

Type: SwitchParameter
Parameter Sets: (All)
Aliases: wi

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-Confirm

Prompts you for confirmation before running the cmdlet.

Type: SwitchParameter
Parameter Sets: (All)
Aliases: cf

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-ProgressAction

{{ Fill ProgressAction Description }}

Type: ActionPreference
Parameter Sets: (All)
Aliases: proga

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

CommonParameters

This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.

INPUTS

OUTPUTS

NOTES