今天早上上班打开电脑,便大吃一惊,PowerShell 无法打开了,于是我在 psmux 里配置的开发环境就无法启动,没有 psmux 我都不知道该怎么启动调试环境。。。我 PowerShell 版本是 7.6.6。
PowerShell 报错
一打开就报错,我重启系统,重新进入,还是报错:
totalwidth (‘-17’) must be a non-negative value. (parameter ‘totalwidth’)
具体报错是:
PowerShell 7.6.6
Process terminated.
totalWidth ('-17') must be a non-negative value. (Parameter 'totalWidth')
Actual value was -10.
at System.Environment.FailFast(System.Runtime.CompilerServices.StackCrawlMarkHandle, System.String, System.Runtime.CompilerServices.ObjectHandleOnStack, System.String)
at System.Environment.FailFast(System.Threading.StackCrawlMark ByRef, System.String, System.Exception, System.String)
at System.Environment.FailFast(System.String, System.Exception)
at Microsoft.PowerShell.UnmanagedPSEntry.Start(System.String[], Int32)
at Microsoft.PowerShell.ManagedPSEntry.Main(System.String[])
System.ArgumentOutOfRangeException: totalWidth ('-10') must be a non-negative value. (Parameter 'totalWidth')
Actual value was -10.
at System.ArgumentOutOfRangeException.ThrowNegative[T](T value, String paramName)
at System.String.PadRight(Int32 totalWidth, Char paddingChar)
at Microsoft.PowerShell.UpdatesNotification.ShowUpdateNotification(PSHostUserInterface hostUI)
at Microsoft.PowerShell.ConsoleHost.Start(String bannerText, String helpText, Boolean issProvidedExternally)
at Microsoft.PowerShell.UnmanagedPSEntry.Start(String[] args, Int32 argc)
我一开始以为是双屏幕造成的,切换了不同屏幕,每个屏幕上最大化也不行。彻底没有办法了。
好在在 github 上找到了解决方案。而且就是这两天的讨论。
https://github.com/PowerShell/PowerShell/issues/28131
解决办法
启动 Windows 命令行,即,cmd 命令行,输入下面命令
setx POWERSHELL_UPDATECHECK Off
这个命令的作用是,禁用 PowerShell 的更新检测。
执行之后,再关闭终端,再打开 PowerShell 就能正常使用了。。。没想到微软还能出这么恐怖的 bug。
问题出在哪里
我大概浏览了一下 github 上那个 issue 的讨论,看起来都是中日韩三种语言出了问题。
然后开发组的程序员一小时前还在回复:
The PowerShell team has decided to remove the Update Notification feature as it provides increasingly limited additional value nowadays.
真的大无语。