【问题标题】:Powershell ISE cannot start after (foolishly) deleting all variables(愚蠢地)删除所有变量后,Powershell ISE 无法启动
【发布时间】:2011-04-14 17:03:12
【问题描述】:

在我急切地想知道哪些变量是受保护的或常量时,我​​决定看看哪些是可以被删除的——假设上面提到的那些将被单独留下。我没有意识到这些变量的删除不仅限于本次 ISE 会议的范围,而且不仅是 PowerShell 全局的,而且是系统全局的。我希望有人可以帮助我让 ISE 重新工作。

我的愚蠢:

Remove-Variable *  

...导致报告了一堆错误,之后我执行 dir variable: 时只剩下少数 (10-15) 个错误。认为这没什么大不了的,并且重新启动 ISE 会使我恢复正常,我关闭了它 - 我无法再启动它了。

其他症状

从那以后我发现我丢失了诸如环境变量 %windir% 之类的东西 - 这是一个最有趣的转折,阻止您打开高级系统设置(找不到 %windir%\system32\systempropertiesadvanced.exe)来设置您的ENV备份...(是的,我可以直接运行它)

更新:我发现了一个额外的影响/症状:Windows 报告说,在自动更新无法正常工作后,我可能没有正版 Windows。我没有意识到像一些 ENV vars 消失这样简单的事情会杀死它。嗯。

那么 - 任何人都知道如何恢复或重新创建成功运行 ISE 所需的环境?

(是的,我已经尝试删除并重新添加该功能,并结合重新启动。)

【问题讨论】:

  • 你一定做了别的事情。删除变量只会影响您当前的 PowerShell 会话,除非您的设置非常不标准。
  • 我期待完全相同的事情 - 只是一个会话更改,但在运行命令后, HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment 被减少到只有几个值。我现在注意到 ISE 默认在这台机器上以管理员身份运行 - 而它对我的任何其他机器都没有特权。好奇 - 我没有手动提升它。虽然我猜这可能是差异以及为什么它不受范围限制。感谢您的帮助!

标签: powershell powershell-ise


【解决方案1】:

我刚才在 ISE 中删除了变量 *,但什么也没发生。我仍然可以打开 ISE 并照常工作。我还做了一个-WhatIf 来查看真正被删除的内容。

PS H:\> Remove-Variable * -WhatIf
What if: Performing operation "Remove Variable" on Target "Name: null".
What if: Performing operation "Remove Variable" on Target "Name: false".
What if: Performing operation "Remove Variable" on Target "Name: true".
What if: Performing operation "Remove Variable" on Target "Name: MaximumErrorCount".
What if: Performing operation "Remove Variable" on Target "Name: MaximumVariableCount".
What if: Performing operation "Remove Variable" on Target "Name: MaximumFunctionCount".
What if: Performing operation "Remove Variable" on Target "Name: MaximumAliasCount".
What if: Performing operation "Remove Variable" on Target "Name: MaximumDriveCount".
What if: Performing operation "Remove Variable" on Target "Name: Error".
What if: Performing operation "Remove Variable" on Target "Name: PWD".
What if: Performing operation "Remove Variable" on Target "Name: ?".
What if: Performing operation "Remove Variable" on Target "Name: MaximumHistoryCount".
What if: Performing operation "Remove Variable" on Target "Name: Host".
What if: Performing operation "Remove Variable" on Target "Name: HOME".
What if: Performing operation "Remove Variable" on Target "Name: ExecutionContext".
What if: Performing operation "Remove Variable" on Target "Name: PSVersionTable".
What if: Performing operation "Remove Variable" on Target "Name: PID".
What if: Performing operation "Remove Variable" on Target "Name: PSCulture".
What if: Performing operation "Remove Variable" on Target "Name: PSUICulture".
What if: Performing operation "Remove Variable" on Target "Name: ShellId".
What if: Performing operation "Remove Variable" on Target "Name: PSHOME".
What if: Performing operation "Remove Variable" on Target "Name: ConsoleFileName".
What if: Performing operation "Remove Variable" on Target "Name: $".
What if: Performing operation "Remove Variable" on Target "Name: ^".
What if: Performing operation "Remove Variable" on Target "Name: StackTrace".
What if: Performing operation "Remove Variable" on Target "Name: OutputEncoding".
What if: Performing operation "Remove Variable" on Target "Name: ConfirmPreference".
What if: Performing operation "Remove Variable" on Target "Name: DebugPreference".
What if: Performing operation "Remove Variable" on Target "Name: ErrorActionPreference".
What if: Performing operation "Remove Variable" on Target "Name: ProgressPreference".
What if: Performing operation "Remove Variable" on Target "Name: VerbosePreference".
What if: Performing operation "Remove Variable" on Target "Name: WarningPreference".
What if: Performing operation "Remove Variable" on Target "Name: ErrorView".
What if: Performing operation "Remove Variable" on Target "Name: NestedPromptLevel".
What if: Performing operation "Remove Variable" on Target "Name: ReportErrorShowExceptionClass".
What if: Performing operation "Remove Variable" on Target "Name: ReportErrorShowInnerException".
What if: Performing operation "Remove Variable" on Target "Name: ReportErrorShowSource".
What if: Performing operation "Remove Variable" on Target "Name: ReportErrorShowStackTrace".
What if: Performing operation "Remove Variable" on Target "Name: WhatIfPreference".
What if: Performing operation "Remove Variable" on Target "Name: FormatEnumerationLimit".
What if: Performing operation "Remove Variable" on Target "Name: PSEmailServer".
What if: Performing operation "Remove Variable" on Target "Name: PSSessionOption".
What if: Performing operation "Remove Variable" on Target "Name: PSSessionConfigurationName".
What if: Performing operation "Remove Variable" on Target "Name: PSSessionApplicationName".
What if: Performing operation "Remove Variable" on Target "Name: psUnsupportedConsoleApplications".
What if: Performing operation "Remove Variable" on Target "Name: PSBoundParameters".
What if: Performing operation "Remove Variable" on Target "Name: args".
What if: Performing operation "Remove Variable" on Target "Name: input".
What if: Performing operation "Remove Variable" on Target "Name: MyInvocation".
What if: Performing operation "Remove Variable" on Target "Name: _".
What if: Performing operation "Remove Variable" on Target "Name: psLocalHelp".
What if: Performing operation "Remove Variable" on Target "Name: psOnlineHelp".
What if: Performing operation "Remove Variable" on Target "Name: psISE".
What if: Performing operation "Remove Variable" on Target "Name: profile".

注意到该列表中的内容非常糟糕。顺便说一句,这些只是 ISE 运行空间中的变量。我不确定删除这些变量会如何阻止 ISE 完全发挥作用。

【讨论】:

  • 正如我上面评论的那样,我猜想提升的 ISE 管理员权限与此有关 - 因为我和你的想法一样!感谢您的帮助!
【解决方案2】:

感谢大家的帮助 - 这就是我所做的,虽然我不确定是否能在所有地方 100% 恢复,但它让我能够使用 ISE、Hyper-V 管理器并再次验证为正版。

我去了另一个 Server 2008 R2 机器,比较密钥并手动编辑注册表并将这些值添加回损坏的机器:

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment
  Path=C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;
  PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC
  PSModulePath=C:\Windows\system32\WindowsPowerShell\v1.0\Modules\
  TEMP=C:\Windows\TEMP
  TMP=C:\Windows\TEMP
  windir=C:\Windows

我倾向于将 ISE 提升的管理员权限作为其影响比会话更大的根本原因。

【讨论】:

  • 我注意到在 Win10 系统上,此引用的“C:\Windows”部分改为 %systemroot%。
猜你喜欢
  • 1970-01-01
  • 2020-05-03
  • 1970-01-01
  • 2013-11-12
  • 2014-01-20
  • 1970-01-01
  • 2015-12-06
  • 1970-01-01
  • 2015-07-25
相关资源
最近更新 更多