简体   繁体   English

从C#执行cmdlet Get-ClusterGroup

[英]Executing cmdlet Get-ClusterGroup from C#

Hi I'm trying to execute the Get-ClusterGroup cmdlet from C# 4.0. 嗨,我正在尝试从C#4.0执行Get-ClusterGroup cmdlet。 I've used the following code 我使用了以下代码

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();

But getting the following error 但是出现以下错误

The term 'Get-ClusterGroup' is not recognized as the name of a cmdlet, function, script file, or operable program. 术语“ Get-ClusterGroup”不能识别为cmdlet,函数,脚本文件或可运行程序的名称。 Check the spelling of the name, or if a path was included, verify that the path is correct and try again. 检查名称的拼写,或者是否包含路径,请验证路径是否正确,然后重试。

It will be great if someone can show me the where I'm missing the logic or where is the problem in my code 如果有人可以告诉我我缺少逻辑的地方或代码中的问题在哪里,那将是很好的

Get-ClusterGroup is a Powershell Commandlet, not an .exe file. Get-ClusterGroup是Powershell Get-ClusterGroup ,而不是.exe文件。 You can invoke Powershell commands from .NET using the System.Management.Automation.PowerShell class, as described on MSDN here: http://msdn.microsoft.com/en-us/library/system.management.automation.powershell(v=vs.85).aspx 您可以使用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