powershell PowerShell:修复PATH系统变量
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了powershell PowerShell:修复PATH系统变量相关的知识,希望对你有一定的参考价值。
$MandatoryOrderedPaths = @(
"$($env:SystemRoot)\System32"
"$($env:SystemRoot)"
"$($env:SystemRoot)\System32\Wbem"
"$($env:SystemRoot)\System32\WindowsPowerShell\v1.0\"
"$($env:SystemRoot)\SysWOW64"
"$($env:SystemRoot)\SysWOW64\Wbem"
"$($env:SystemRoot)\SysWOW64\WindowsPowerShell\v1.0\"
)
# Remove trailing slash in paths
$MandatoryOrderedPaths = $MandatoryOrderedPaths | % {$_.Trimend('\')}
# Get current PATH
$CurrentPaths = $env:PATH -split(';')
# Remove trailing slash in paths
$CurrentPaths = $CurrentPaths | % {$_.Trimend('\')}
# Unique
$CurrentPaths = $CurrentPaths | Sort -Unique
# Path exists
$CurrentPaths = $CurrentPaths | ? {$_} | ? {Test-Path -Path $_ -PathType Container -ErrorAction SilentlyContinue}
# Remove Mandatory from Current
$CurrentPaths = $CurrentPaths | ? {$MandatoryOrderedPaths -notcontains $_}
# Show new PATH
"$($MandatoryOrderedPaths -join ';');$($CurrentPaths -join ';')"
[Environment]::SetEnvironmentVariable("PATH", "$($MandatoryOrderedPaths -join ';');$($CurrentPaths -join ';')", "MACHINE")
以上是关于powershell PowerShell:修复PATH系统变量的主要内容,如果未能解决你的问题,请参考以下文章
powershell Mongodb快速修复
powershell 修复Bug Mongodb
powershell 快速编辑列表修复
powershell 修复木偶
powershell 修复损坏的WU DataStore。
如何修复无法索引到 PowerShell 中的空数组