繁体   English   中英

从C#执行cmdlet Get-ClusterGroup

[英]Executing cmdlet Get-ClusterGroup from C#

嗨,我正在尝试从C#4.0执行Get-ClusterGroup cmdlet。 我使用了以下代码

InitialSessionState iss = InitialSessionState.CreateDefault();
iss.ImportPSModule(new string[] { "failoverclusters"});

Runspace myRunSpace = RunspaceFactory.CreateRunspace(iss);
myRunSpace.Open();

Pipeline pipeLine = myRunSpace.CreatePipeline();

Command myCommand = new Command("Get-ClusterGroup");
pipeLine.Commands.Add(myCommand);

Console.WriteLine("Invoking Command");
Collection commandResult = pipeLine.Invoke();

foreach (PSObject resultObject in commandResult)
{
Console.WriteLine(resultObject.ToString());
}
myRunSpace.Close();

但是出现以下错误

术语“ Get-ClusterGroup”不能识别为cmdlet,函数,脚本文件或可运行程序的名称。 检查名称的拼写,或者是否包含路径,请验证路径是否正确,然后重试。

如果有人可以告诉我我缺少逻辑的地方或代码中的问题在哪里,那将是很好的

Get-ClusterGroup是Powershell Get-ClusterGroup ,而不是.exe文件。 您可以使用System.Management.Automation.PowerShell类从.NET调用Powershell命令,如MSDN此处所述: http : //msdn.microsoft.com/zh-cn/library/system.management.automation.powershell(v = vs.85).aspx

暂无
暂无

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

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