Thanks to visit codestin.com
Credit goes to github.com

Skip to content

adding path cleanup utility Reset-PWSHSystemPath.ps1#6892

Merged
TravisEz13 merged 2 commits intoPowerShell:masterfrom
DarwinJS:add-resetpaths-script
May 22, 2018
Merged

adding path cleanup utility Reset-PWSHSystemPath.ps1#6892
TravisEz13 merged 2 commits intoPowerShell:masterfrom
DarwinJS:add-resetpaths-script

Conversation

@DarwinJS
Copy link
Contributor

@DarwinJS DarwinJS commented May 18, 2018

PR Summary

Cleans up old powershell core paths
Addresses: #6811

PR Checklist

Copy link
Member

@TravisEz13 TravisEz13 left a comment

Choose a reason for hiding this comment

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

please respond to comments

$AssembledNewPath -split ';'
[Environment]::SetEnvironmentVariable("PATH",$AssembledNewPath,"$PathScopeItem")
}
} No newline at end of file
Copy link
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
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

{
$AssembledNewPath = $NewPath = ''
$pathstoremove = @([Environment]::GetEnvironmentVariable("PATH","$PathScopeItem").split(';') | Where { $_ -ilike "*\Program Files\Powershell\6*"})
If (!$RemoveAllOccurences)
Copy link
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

{
$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
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
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 TravisEz13 merged commit 862d99f into PowerShell:master May 22, 2018
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