Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Windows Powershell立即关闭_Windows_Powershell_Windows 10 - Fatal编程技术网

Windows Powershell立即关闭

Windows Powershell立即关闭,windows,powershell,windows-10,Windows,Powershell,Windows 10,我查阅了所有的互联网,但我找不到任何适用于这种情况的信息 Powershell在启动后立即关闭。当我在命令提示符下运行它时,会得到以下结果: Windows PowerShell terminated with the following error: Unable to cast object of type 'System.String' to type 'System.String[]'. 我已检查以下文件夹,但不存在任何配置文件: c:\users\me\appdata\micros

我查阅了所有的互联网,但我找不到任何适用于这种情况的信息

Powershell在启动后立即关闭。当我在命令提示符下运行它时,会得到以下结果:

Windows PowerShell terminated with the following error:
 Unable to cast object of type 'System.String' to type 'System.String[]'.
我已检查以下文件夹,但不存在任何配置文件:

c:\users\me\appdata\microsoft\windows\powershell

c:\windows\system32\windowspowershell\v1.0\

c:\windows\systwow64\windowspowershell\v1.0\

我尝试使用以下命令运行,但没有成功:

powershell-noexit

powershell-noprofile

我已运行以下命令,但运气不佳:

sfc.exe/scannow

DISM.exe/Online/Cleanup image/Restorehealth

我还去了控制面板->卸载程序->打开或关闭Windows功能, 已删除Powershell,重新启动,然后重新安装


完成所有这些步骤后,我仍然无法运行Powershell。ISE也不工作。

无论何时运行powershell,它都会加载模块目录中的默认模块。其中一个模块(很可能是您编写的自定义模块)导致错误,不允许您启动

如果不知道位于以下目录中的模块:C:\windows\system32\windowspowershell\v1.0\modules,任何人都很难告诉您解决方案

建议

删除其中的所有自定义模块,并逐个添加所需的每个模块,以查看哪个模块会破坏powershell.exe。您还需要检查为要加载的自定义模块定义的每个路径

另一种方法是从环境变量中清除PSModulePath,并一次添加一个位置,直到看到哪个
模块
目录导致错误

注意:在清除之前,在记事本的某个地方写下路径


从错误来看,它似乎是一个未正确写入的.net库类(dll)。

这可能与Powershell日志记录设置有关。在使用
ModuleNames
的错误路径实现Powershell模块日志记录后,我遇到了完全相同的问题

检查
HKEY\U LOCAL\U MACHINE\SOFTWARE\Policys\Microsoft\Windows\PowerShell\ModuleLogging

在我的例子中,我犯了一个错误,将
ModuleNames
的值添加到
*
-没有意识到它应该是一个名为
ModuleNames
的键,这导致了一个错误

通过添加正确的路径
HKEY\U LOCAL\U MACHINE\SOFTWARE\Policys\Microsoft\Windows\PowerShell\ModuleLogging\ModuleNames\
,路径名为
*
,路径值为
*
,我使PowerShell重新工作


请注意,如果此设置来自域中的GPO(组策略对象),则需要将其固定在该域中,而不是在注册表中。否则,GPO将在下次应用时覆盖本地设置。

我没有自定义模块。请从系统的环境变量中清除PSModulePath,然后尝试运行powreshell.exe,看看是否有效。写下可以恢复的值是否有办法完全删除Powershell并重新插入?删除最新的.net framework更新,然后重新安装。除此之外,我想的也不多。正如我上面提到的,您不能完全删除并重新安装Windows PowerShell。除非是您手动安装的v3-v5x版本升级(Jawad暗示的.Net升级),或者是PowerShell Core,您可以与旧版Windows PowerShell并排安装。[1]ISE工作吗?[2] 你能在控制台中运行一个简单的脚本吗?[3] 对于
powershell.exe
,没有
-NoClose
参数。有一个
-NoExit
参数tho。[咧嘴笑]我更新了它来回答这些问题-NoExit是我想说的,好球。ISE不工作。您也无法在Windows上卸载Powershell。该功能适用于PowerShell v2。根据微软发布的所有公告,这几天真的应该被禁用。如果您使用的是Win 10,则PSV版本为v4-5x。如果您安装了PowerShell v7(PowerShell Core),则可以随意安装和卸载。但是,Windows PowerShell是操作系统的一部分。如果恢复点正常工作,您是否有可以返回的恢复点?
Windows PowerShell terminated with the following error:
Unable to cast object of type 'System.String' to type 'System.String[]'.