Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/13.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
C# 为什么可以';从c中的Powershell.Invoke()方法返回所有cimsession函数#_C#_Powershell_Psobject - Fatal编程技术网

C# 为什么可以';从c中的Powershell.Invoke()方法返回所有cimsession函数#

C# 为什么可以';从c中的Powershell.Invoke()方法返回所有cimsession函数#,c#,powershell,psobject,C#,Powershell,Psobject,我正在从Powershell和C#运行New CimSession命令。当我在Powershell上运行它时,CimSession变量有很多函数,比如TestConnection(),CreateInstance等等。。图片如下 但是,CimSession变量类型的PSObject除了ToString()和GetType()之外,没有其他函数,当我在c#中运行New CimSession命令时 我想从c#上的PSObject变量访问相同的方法。 你有什么想法吗? 添加对Microsoft.Ma

我正在从Powershell和C#运行
New CimSession
命令。当我在Powershell上运行它时,CimSession变量有很多函数,比如
TestConnection()
CreateInstance
等等。。图片如下

但是,
CimSession
变量类型的
PSObject
除了
ToString()
GetType()
之外,没有其他函数,当我在c#中运行
New CimSession
命令时

我想从c#上的
PSObject
变量访问相同的方法。 你有什么想法吗?

  • 添加对Microsoft.Management.Infrastructure命名空间的引用
  • 添加“使用Microsoft.Management.Infrastructure”
c会话
将可以访问所需的不同方法

此处引用:

  • “C:\Program Files(x86)\Reference Assembly\Microsoft\WMI\v1.0\Microsoft.Management.Infrastructure.dll”

  • C:\Windows\Microsoft.NET\assembly\GAC\U MSIL\Microsoft.Management.Infrastructure

      • 添加对Microsoft.Management.Infrastructure命名空间的引用
      • 添加“使用Microsoft.Management.Infrastructure”
      c会话
      将可以访问所需的不同方法

      此处引用:

      • “C:\Program Files(x86)\Reference Assembly\Microsoft\WMI\v1.0\Microsoft.Management.Infrastructure.dll”

      • C:\Windows\Microsoft.NET\assembly\GAC\U MSIL\Microsoft.Management.Infrastructure


      嗨,Emre,让我知道解决方案是否有效嗨,Emre,让我知道解决方案是否有效是的,你是对的。这种方式有帮助,但我的项目是.NETFramework4.8。我犯了这个错误。无法安装程序包“Microsoft.Management.Infrastructure.Runtime.Unix 2.0.0”。您正试图将此程序包安装到以“.NETFramework,Version=v4.8”为目标的项目中,但该程序包不包含任何与该框架兼容的程序集引用或内容文件。有关详细信息,请与程序包作者联系是的,我试图使用Nuget,但我查看了.dll,但没有C:\Program Files(x86)\Reference Assembly\Microsoft\WMI\v1.0“是的,非常感谢。我在那里找到的。现在,我将尝试在项目中实现它。当然很好,如果它有效,你可以接受我的答案!!是的,你说得对。这种方式有帮助,但我的项目是.NETFramework4.8。我犯了这个错误。无法安装程序包“Microsoft.Management.Infrastructure.Runtime.Unix 2.0.0”。您正试图将此程序包安装到以“.NETFramework,Version=v4.8”为目标的项目中,但该程序包不包含任何与该框架兼容的程序集引用或内容文件。有关详细信息,请与程序包作者联系是的,我试图使用Nuget,但我查看了.dll,但没有C:\Program Files(x86)\Reference Assembly\Microsoft\WMI\v1.0“是的,Windows 10真的很感谢。我在那里找到了。现在,我将尝试在project中实现它。当然很好,如果它有效,您可以接受我的答案!!
      static void Main(string [] args)
      {
           var csession = CimSession.Create("");
           csession.TestConnection();
      }