繁体   English   中英

发生异常:运行简单 PowerShell 命令时出现 CLR/System.Management.Automation.Runspaces.PSSnapInException

[英]Exception has occurred: CLR/System.Management.Automation.Runspaces.PSSnapInException when running simple PowerShell command

我正在尝试运行一个示例 C# 程序,该程序应该调用一个简单的 PowerShell 命令。 不幸的是,我收到以下错误消息:

Exception has occurred: CLR/System.Management.Automation.Runspaces.PSSnapInException
An unhandled exception of type 'System.Management.Automation.Runspaces.PSSnapInException' occurred in System.Management.Automation.dll: 'System error.'
   at System.Management.Automation.Runspaces.PSSnapInHelpers.LoadPSSnapInAssembly(PSSnapInInfo psSnapInInfo)
   at System.Management.Automation.Runspaces.InitialSessionState.ImportPSSnapIn(PSSnapInInfo psSnapInInfo, PSSnapInException& warning)
   at System.Management.Automation.Runspaces.InitialSessionState.CreateDefault()
   at System.Management.Automation.Runspaces.RunspaceFactory.CreateRunspace(PSHost host)
   at System.Management.Automation.Runspaces.RunspaceFactory.CreateRunspace()
   at System.Management.Automation.PowerShell.Worker.CreateRunspaceIfNeededAndDoWork(Runspace rsToUse, Boolean isSync)
   at System.Management.Automation.PowerShell.CoreInvokeHelper[TInput,TOutput](PSDataCollection`1 input, PSDataCollection`1 output, PSInvocationSettings settings)
   at System.Management.Automation.PowerShell.CoreInvoke[TInput,TOutput](PSDataCollection`1 input, PSDataCollection`1 output, PSInvocationSettings settings)
   at System.Management.Automation.PowerShell.Invoke(IEnumerable input, PSInvocationSettings settings)
   at System.Management.Automation.PowerShell.Invoke()
   at ttps3.Program.Main(String[] args) in Z:\projects\easybell\ttps3\Program.cs:line 21

我在 C# SDK 5 和 System.Management.Automation 7.1.3 上运行

System.Management.Automation仅在非常有限的场景中可用。 您可以安装Microsoft.PowerShell.SDK nuget ZEFE90A8E604A7C840E88D03A67F。

微软.PowerShell.SDK

Microsoft.PowerShell.SDK is a meta-package that pulls together all of the components of the PowerShell SDK into a single NuGet package. A self-contained .NET application can use Microsoft.PowerShell.SDK to run arbitrary PowerShell functionality without depending on any external PowerShell installations or libraries.

系统管理自动化

The System.Management.Automation package is the heart of the PowerShell SDK and exists on NuGet chiefly as an asset for Microsoft.PowerShell.SDK to pull in. However, it can also be used directly as a package for smaller hosting scenarios and version-目标模块。

具体来说,在以下情况下, System.Management.Automation package 可能是 PowerShell 功能的更好提供者:

  • 您只想使用 PowerShell 解析器、AST 和 AST 访问者 API(例如用于分析 PowerShell 的 ZA81259CEF8E959C624DF1D45ZE)等 PowerShell 语言功能(在System.Management.Automation.Language命名空间中)。
  • 您只希望从Microsoft.PowerShell.Core模块执行特定命令,并且可以在使用CreateDefault2工厂方法创建的 session state 中执行它们。

PowerShellStandard.Library 和其他 PowerShell 参考程序集

这些参考程序集不包括运行时,并且需要与参考程序集版本匹配的全局 powershell 安装。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM