C# Citrix to Powershell

本文关键字:Powershell to Citrix | 更新日期: 2023-09-27 18:36:33

我们开发了一个新的基于Web的应用程序,该应用程序通过C#调用Citrix Xenapp Powershell cmdlet。Web 应用程序托管在 Citrix 服务器(这已经在农场中)本身上,我们认为这足以访问 Citrix 服务器场中的所有服务器。该代码在从Visual Studio IDE运行时提供输出。但是,当我在IIS上创建一个虚拟目录并通过浏览器访问它时。

at

System.Management.Automation.Internal.PipelineProcessor.SynchronousExecuteEnumerate(Object input, Hashtable errorResults, Boolean enumerate) at System.Management.Automation.Runspaces.LocalPipeline.InvokeHelper() at System.Management.Automation.Runspaces.LocalPipeline.InvokeThreadProc()

以下是代码

protected void Page_Load(object sender, EventArgs e)
{
    string usrname = "";
    string svrname = "";
    string appname = "";
    string clntnme = "";
    string clntip="";
    string farm = "";
    Runspace rsp = RunspaceFactory.CreateRunspace();
    //rsp.ApartmentState = System.Threading.ApartmentState.STA;
    //rsp.ThreadOptions = PSThreadOptions.UseCurrentThread;
    rsp.Open();
    PSSnapInException exp;
    rsp.RunspaceConfiguration.AddPSSnapIn("Citrix.XenApp.Commands", out exp);
    try
    {
        PowerShell ps3 = PowerShell.Create().AddCommand("Get-XAFarm");
        ps3.Runspace = rsp;
        foreach (PSObject pss in ps3.Invoke())
        {
            farm = pss.Properties["FarmName"].Value.ToString();
        }
        Response.Write("<DIV align=" + "center" + " style=" + "width:100%;height:100%" + ">" + farm + "<TABLE style=" + "width:100%" + ">");
        Response.Write("<TR><TH>User</TH><TH>Server</TH><TH>Application</TH><TH>Address</TH><TH>Client Name</TH></TR>");
        PowerShell sessions = PowerShell.Create().AddCommand("Get-XASession").AddParameter("Full").AddCommand("where-object").AddParameter("FilterScript", ScriptBlock.Create("{$_.BrowserName -ne $null }"));
        sessions.Runspace = rsp;
        foreach (PSObject psr in sessions.Invoke())
        {
            //IPAddress.Parse(psr.Properties["ClientAddress"].Value.ToString());
            usrname = psr.Properties["AccountName"].Value.ToString();
            svrname = psr.Properties["ServerName"].Value.ToString();
            appname = psr.Properties["BrowserName"].Value.ToString();
            clntnme = psr.Properties["ClientName"].Value.ToString();
            //if (psr.Properties["ClientAddress"].Value != null)
            //{
                clntip = psr.Properties["ClientAddress"].Value.ToString();
            //}
            //clntip = psr.Properties["ClientIPV4"].Value.ToString();
            Response.Write("<TR><TD>" + usrname + "</TD><TD>" + svrname + "</TD><TD>" + appname + "</TD><TD>" + clntip + "</TD><TD>" + clntnme + "</TD></TR>");
        }
        Response.Write("</TABLE>");
    }
    catch (Exception ex)
    {
        Response.Write(ex.StackTrace.ToString());
    }
    finally
    {
        rsp.Close();
    }
}**

如果必须在 IIS 上进行任何更改才能使我成功访问aspx页面,请告诉我。

C# Citrix to Powershell

应用程序需要以在 XenApp 场中具有足够管理员权限的用户身份运行。您可以创建一个专用服务帐户,并将其设为 XenApp 场中的管理员。要像示例一样列出场状态,它只需要是"仅查看"XenApp 管理员。然后将 IIS 配置为作为该服务帐户运行。