简体   繁体   English

为什么我不能从 c# 中的 Powershell.Invoke() 方法返回所有 cimsession 函数

[英]Why can't i return all cimsession functions from Powershell.Invoke() method in c#

I'm running New-CimSession command from both Powershell and C#.我正在从 Powershell 和 C# 运行New-CimSession命令。 When I run it on Powershell, CimSession variable has a lot of functions such as TestConnection() , CreateInstance etc.. Picture is below.当我在 Powershell 上运行它时,CimSession 变量有很多功能,例如TestConnection()CreateInstance等。图片如下。

在此处输入图片说明

But, CimSession variable type of PSObject doesn't have others functions except ToString() and GetType() , when I run New-CimSession command from Powershell.Invoke() method in c#.但是, CimSession的变量类型PSObject没有其他功能除了ToString()GetType()当我运行New-CimSession从命令Powershell.Invoke()方法在C#。

I want to access same method from PSObject variable on c#.我想从 c# 上的PSObject变量访问相同的方法。 Do you have a idea?你有什么想法吗?

  • Add Reference to Microsoft.Management.Infrastructure Namespace添加对Microsoft.Management.Infrastructure Namespace引用
  • Add `using Microsoft.Management.Infrastructure;添加`使用Microsoft.Management.Infrastructure;
static void Main(string [] args)
{
     var csession = CimSession.Create("");
     csession.TestConnection();
}

csession will have access to different Methods you want csession将可以访问您想要的不同方法

Reference here:参考这里:

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

  • C:\\Windows\\Microsoft.NET\\assembly\\GAC_MSIL\\Microsoft.Management.Infrastructure C:\\Windows\\Microsoft.NET\\assembly\\GAC_MSIL\\Microsoft.Management.Infrastructure

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

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