2

有没有人使用过 Citrix 7.6 BrokerSession SDK?我不知道如何执行这样的命令,例如:

GetBrokerSessionCommand getCmd = new GetBrokerSessionCommand();
getCmd.AdminAddress = "citrixServer:80";
var result = getCmd.Invoke();

这给了我一条错误消息:“不能直接调用从 PSCmdlet 派生的 Cmdlet。

在早期的 6.5 SDK 中,我可以这样做:

string[] servers = new string[] { };
GetXAWorkerGroupByName workerGroup = new GetXAWorkerGroupByName();
workerGroup.WorkerGroupName = new string[] { workerGroupName };
workerGroup.ComputerName = XenAppController;
foreach (XAWorkerGroup _workerGroup in CitrixRunspaceFactory.DefaultRunspace.ExecuteCommand(workerGroup))
                {
                    servers = _workerGroup.ServerNames;
                }

            return servers;

但是现在 CitrixRunspaceFactory 已经不存在了?出于以更简单的方式处理异常的简单原因,我想避免使用 Powershell 类和 Powershell.Create() 执行命令。

4

1 回答 1

1

Citrix 7.6 cmdlet 不是从 Cmdlet 类而是从 PSCmdlet 派生的。因此它们更多地绑定到 PowerShell 引擎,并且必须在其中调用:

    Runspace runSpace = RunspaceFactory.CreateRunspace();
    runSpace.Open();
    PSSnapInException psex;
    runSpace.RunspaceConfiguration.AddPSSnapIn("Citrix.Broker.Admin.V2", out psex);
    Pipeline pipeline = runSpace.CreatePipeline();

    Command getSession = new Command("Get-BrokerSession");
    getSession.Parameters.Add("AdminAddress", "SERVERNAME");
    pipeline.Commands.Add(getSession);

    Collection<PSObject> output = pipeline.Invoke();

Citrix SDK 中强类型类的 AFAIK 好时光已经一去不复返了。

于 2015-10-06T14:56:39.627 回答