Skip to content

adding path cleanup utility Reset-PWSHSystemPath.ps1 - #6892

Merged
Travis Plunk (TravisEz13) merged 2 commits into
PowerShell:masterfrom
DarwinJS:add-resetpaths-script
May 22, 2018
Merged

adding path cleanup utility Reset-PWSHSystemPath.ps1#6892
Travis Plunk (TravisEz13) merged 2 commits into
PowerShell:masterfrom
DarwinJS:add-resetpaths-script

Conversation

@DarwinJS

@DarwinJS Darwin (DarwinJS) commented May 18, 2018

Copy link
Copy Markdown
Contributor

PR Summary

Cleans up old powershell core paths
Addresses: #6811

PR Checklist

@TravisEz13 Travis Plunk (TravisEz13) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please respond to comments

Comment thread tools/windows/Reset-PWSHSystemPath.ps1 Outdated
$AssembledNewPath -split ';'
[Environment]::SetEnvironmentVariable("PATH",$AssembledNewPath,"$PathScopeItem")
}
} No newline at end of file

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add an ending newline, please?

ForEach ($PathScopeItem in $PathScope)
{
$AssembledNewPath = $NewPath = ''
$pathstoremove = @([Environment]::GetEnvironmentVariable("PATH","$PathScopeItem").split(';') | Where { $_ -ilike "*\Program Files\Powershell\6*"})

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a comment like get all parts of the path that are like a powershell core path

Comment thread tools/windows/Reset-PWSHSystemPath.ps1 Outdated
{
$AssembledNewPath = $NewPath = ''
$pathstoremove = @([Environment]::GetEnvironmentVariable("PATH","$PathScopeItem").split(';') | Where { $_ -ilike "*\Program Files\Powershell\6*"})
If (!$RemoveAllOccurences)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add a comment like filter to all but the last instance, unless remove all occurrences is specified

Comment thread tools/windows/Reset-PWSHSystemPath.ps1 Outdated
{
$pathstoremove = @($pathstoremove | sort-object | Select-Object -skiplast 1)
}
Write-Host "Reset-PWSHSystemPath: Found $($pathstoremove.count) paths to remove from $PathScopeItem path scope: $($Pathstoremove -join ', ' | out-string)"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not blocking: The use of write-host could prevent the use of this script in automation. Write-verbose is prefered

{
foreach ($path in [Environment]::GetEnvironmentVariable("PATH","$PathScopeItem").split(';'))
{
If ($Path)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

even though PowerShell is not case sensitive, the best practice is to use the same case for the same variable.

@TravisEz13
Travis Plunk (TravisEz13) merged commit 862d99f into PowerShell:master May 22, 2018
Thatgfsj (Thatgfsj) pushed a commit to Thatgfsj-contribs/PowerShell that referenced this pull request Aug 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants