XenApp: Automated Server Desktop publishing using PowerShell


Purpose:

To publish Server Desktop running XenApp automatically using PowerShell script.

Pre-requisite:

Following are the prerequisites for setting up the environment to execute PowerShell script to publish application in XenApp:

  1. .Net Framework 3.5 SP1 {Download it from Microsoft website}
  2. Microsoft PowerShell 1.0 {Download it from Microsoft website}
  3. XenApp Command technology preview{Download it from citrix site: https://www.citrix.com/English/ss/downloads/details.asp?downloadId=1687620&productId=186#top} : These commands are a PowerShell Tool Pack that allows managing most aspects related to XenApp.  They cover all of MFCOM functionality for features available in XenApp 5 and include functionality from both AMC and CMC.

Install all the above components in the given order onto the XenApp environment.

Solution: 

Below script is the solution. It has five parts:

  • Creation of input box for application information – {Line 9 – 98}
  • Creation of new folder under Applications folder {Applications/Desktops} – {Line 100}
  • Creation the published desktop – {Line 102-111}
  • Addition of users/groups to the application –{Line 113-114}
  • Assignment of servers to the published app –{Line 116-117}

    Script:

       1: # ============================================================

       2: # 

       3: # AUTHOR: Mohd Aslam

       4: # DATE  : 6/23/2010

       5: # 

       6: # COMMENT: This script publishes Server desktop running XenApp

       7: # 

       8: # ============================================================

       9: [void] [System.Reflection.Assembly]::LoadWithPartialName(

      10: "System.Drawing") 

      11: [void] [System.Reflection.Assembly]::LoadWithPartialName(

      12: "System.Windows.Forms") 

      13:  

      14: $objForm = New-Object System.Windows.Forms.Form 

      15: $objForm.Text = "Server Desktop publish information"

      16: $objForm.Size = New-Object System.Drawing.Size(430,200) 

      17: $objForm.StartPosition = "CenterScreen"

      18:  

      19: $objForm.KeyPreview = $True

      20: $objForm.Add_KeyDown({if ($_.KeyCode -eq "Enter") 

      21:     {$x=$objTextBox.Text;$objForm.Close()}})

      22: $objForm.Add_KeyDown({if ($_.KeyCode -eq "Escape") 

      23:     {$objForm.Close()}})

      24:  

      25: $OKButton = New-Object System.Windows.Forms.Button

      26: $OKButton.Location = New-Object System.Drawing.Size(190,140)

      27: $OKButton.Size = New-Object System.Drawing.Size(75,23)

      28: $OKButton.Text = "OK"

      29: $OKButton.Add_Click(

      30: {

      31: $AppName=$objAppName.Text;

      32: $AppUsers=$objAppUsers.Text;

      33: $AppServers=$objAppServers.Text;

      34: $objForm.Close()

      35: }

      36: )

      37: $objForm.Controls.Add($OKButton)

      38:  

      39: $CancelButton = New-Object System.Windows.Forms.Button

      40: $CancelButton.Location = New-Object System.Drawing.Size(290,140)

      41: $CancelButton.Size = New-Object System.Drawing.Size(75,23)

      42: $CancelButton.Text = "Cancel"

      43: $CancelButton.Add_Click(

      44: {

      45: $objForm.Close()

      46: }

      47: )

      48: $objForm.Controls.Add($CancelButton)

      49:  

      50: $objLabel = New-Object System.Windows.Forms.Label

      51: $objLabel.Location = New-Object System.Drawing.Size(10,15) 

      52: $objLabel.Size = New-Object System.Drawing.Size(280,20) 

      53: $objLabel.Text = "Please enter the information in the space below:"

      54: $objForm.Controls.Add($objLabel) 

      55:  

      56: $objLbl_AppName = New-Object System.Windows.Forms.Label

      57: $objLbl_AppName.Location = New-Object System.Drawing.Size(10,40) 

      58: $objLbl_AppName.Size = New-Object System.Drawing.Size(160,20) 

      59: $objLbl_AppName.Text = "Publish Name:"

      60: $objForm.Controls.Add($objLbl_AppName) 

      61:  

      62: $objAppName = New-Object System.Windows.Forms.TextBox 

      63: $objAppName.Location = New-Object System.Drawing.Size(190,40) 

      64: $objAppName.Size = New-Object System.Drawing.Size(205,20) 

      65: $objForm.Controls.Add($objAppName) 

      66:  

      67: $objLbl_AppUsers = New-Object System.Windows.Forms.Label

      68: $objLbl_AppUsers.Location = New-Object System.Drawing.Size(10,70) 

      69: $objLbl_AppUsers.Size = New-Object System.Drawing.Size(160,20) 

      70: $objLbl_AppUsers.Text = "Application Users*:"

      71: $objForm.Controls.Add($objLbl_AppUsers) 

      72:  

      73: $objAppUsers = New-Object System.Windows.Forms.TextBox 

      74: $objAppUsers.Location = New-Object System.Drawing.Size(190,70) 

      75: $objAppUsers.Size = New-Object System.Drawing.Size(205,20) 

      76: $objForm.Controls.Add($objAppUsers) 

      77:  

      78: $objLbl_Server = New-Object System.Windows.Forms.Label

      79: $objLbl_Server.Location = New-Object System.Drawing.Size(10,100) 

      80: $objLbl_Server.Size = New-Object System.Drawing.Size(160,20) 

      81: $objLbl_Server.Text = "Servers*:"

      82: $objForm.Controls.Add($objLbl_Server) 

      83:  

      84: $objAppServers = New-Object System.Windows.Forms.TextBox 

      85: $objAppServers.Location = New-Object System.Drawing.Size(190,100) 

      86: $objAppServers.Size = New-Object System.Drawing.Size(205,20) 

      87: $objForm.Controls.Add($objAppServers) 

      88:  

      89: $objLbl_Server = New-Object System.Windows.Forms.Label

      90: $objLbl_Server.Location = New-Object System.Drawing.Size(10,120) 

      91: $objLbl_Server.Size = New-Object System.Drawing.Size(180,20) 

      92: $objLbl_Server.Text = "*: Enter ';' separated data if any"

      93: $objForm.Controls.Add($objLbl_Server) 

      94:  

      95: $objForm.Topmost = $True

      96:  

      97: $objForm.Add_Shown({$objForm.Activate()})

      98: [void] $objForm.ShowDialog()

      99:  

     100: New-XAFolder Applications/Desktops

     101:  

     102: New-XAApplication -BrowserName $AppName `

     103: -ApplicationType "ServerDesktop" `

     104: -DisplayName $AppName -FolderPath "Applications/Desktops" `

     105: -Enabled $true `

     106: -AnonymousConnectionsAllowed $false `

     107: -AddToClientStartMenu $false `

     108: -InstanceLimit "-1" `

     109: -ColorDepth 1 `

     110: -AudioRequired $false `

     111: -ClientFolder "Desktops"`

     112:  

     113: Add-XAApplicationAccount -BrowserName $AppName `

     114: -Accounts $AppUsers.Split(";")

     115:  

     116: Add-XAApplicationServer -BrowserName $AppName `

     117: -ServerNames $AppServers.Split(";")

     118:  

     119:  

     120:  

     How to Run above script?:

    Save above script to some location with .ps1 extension. To Run above script, go to “Programs > Citrix > XenApp Commands” and click “Windows PowerShell with XenApp Commands (CTP2)” icon. It will launch PowerShell command prompt.

    On the PowerShell command prompt, write script name with full location and click enter. Script will run and below screen will be displayed:

    image

    Enter all the required data and click “Ok”. For application users and servers, multiple data can be entered separated by “;”.

    Following screen will be displayed containing information about the published icon.

    image

    To confirm the successful publish, go to access management console and see the published icon as:

    image

                                                                    –Finish–

  • Advertisements

    2 thoughts on “XenApp: Automated Server Desktop publishing using PowerShell

    Leave a Reply

    Fill in your details below or click an icon to log in:

    WordPress.com Logo

    You are commenting using your WordPress.com account. Log Out / Change )

    Twitter picture

    You are commenting using your Twitter account. Log Out / Change )

    Facebook photo

    You are commenting using your Facebook account. Log Out / Change )

    Google+ photo

    You are commenting using your Google+ account. Log Out / Change )

    Connecting to %s