adding path cleanup utility Reset-PWSHSystemPath.ps1#6892
adding path cleanup utility Reset-PWSHSystemPath.ps1#6892TravisEz13 merged 2 commits intoPowerShell:masterfrom
Conversation
TravisEz13
left a comment
There was a problem hiding this comment.
please respond to comments
| $AssembledNewPath -split ';' | ||
| [Environment]::SetEnvironmentVariable("PATH",$AssembledNewPath,"$PathScopeItem") | ||
| } | ||
| } No newline at end of file |
There was a problem hiding this comment.
Add an ending newline, please?
| ForEach ($PathScopeItem in $PathScope) | ||
| { | ||
| $AssembledNewPath = $NewPath = '' | ||
| $pathstoremove = @([Environment]::GetEnvironmentVariable("PATH","$PathScopeItem").split(';') | Where { $_ -ilike "*\Program Files\Powershell\6*"}) |
There was a problem hiding this comment.
Add a comment like get all parts of the path that are like a powershell core path
| { | ||
| $AssembledNewPath = $NewPath = '' | ||
| $pathstoremove = @([Environment]::GetEnvironmentVariable("PATH","$PathScopeItem").split(';') | Where { $_ -ilike "*\Program Files\Powershell\6*"}) | ||
| If (!$RemoveAllOccurences) |
There was a problem hiding this comment.
add a comment like filter to all but the last instance, unless remove all occurrences is specified
| { | ||
| $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)" |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
even though PowerShell is not case sensitive, the best practice is to use the same case for the same variable.
PR Summary
Cleans up old powershell core paths
Addresses: #6811
PR Checklist
.h,.cpp,.cs,.ps1and.psm1files have the correct copyright headerWIP:to the beginning of the title and remove the prefix when the PR is ready.[feature]if the change is significant or affects feature tests