I recently gave a presentation on the Citrix XenApp cmdlets for the Atlanta Citrix User Group. For the presentation I wanted to show a real world example of the cmdlets in use. I decided to take a script that I wrote in July of 2007 ,which is still in use today, and convert it to use the new XenApp PowerShell cmdlets. Shown below is the original script.
The purpose of the script is to automatically create a published desktop for our XenApp servers as they are built. It uses MFCOM to perform the work. One of the pain points in this script is that I had to actually copy the icon from an existing published desktop. This is a problem that I don’t have with the cmdlets.
#= Script Name: Citrix Admin Desktop Publishing Script
#= Created On: 07/11/2007
#= Author: Mark E. Schill
#= File: Publish-Desktop.ps1
#= Usage:
#= Version: 1.0
#= Purpose: Publishes an Admin Desktop on the server it is run from.
#= Requirements: Must be run on a Citrix server in the same farm
#= Last Updated: 07/11/2007
#= History:
#= 07/11/2007 1.0 - Initial Revision
#=
#= Copyright (C) 2007 Mark E. Schill
#==============================================================================
function Publish-Desktop( [string]$ServerName)
{
$CPSReferenceApp = New-Object -comOBject MetaFrameCOM.MetaFrameApplication
$CPSReferenceApp.Initialize(3, "Applications/Admin/Desktops/WMT13-CTX-DC1 Desktop")
$CPSReferenceApp.LoadData($true)
$CPSReferenceIcon = $CPSReferenceApp.WinAppObject.IconObject
$ServerName = $ServerName.ToUpper()
$CPSFarm = New-Object -ComObject MetaFrameCOM.MetaFrameFarm
$CPSFarm.Initialize(1)
$CPSApp = $CPSFarm.AddApplication(3)
$CPSApp.AppName = "$ServerName Desktop"
$CPSApp.Description = "Admin Desktop for Remote Administration"
$CPSApp.ParentFolderDN = "Applications/Admin/Desktops"
$CPSApp.PNFolder = "Admin\Desktops"
$CPSApp.WinAppObject.DefaultInitProg = ""
$CPSApp.WinAppObject.DefaultWorkDir = ""
$CPSApp.WinAppObject.DefaultWindowColor = 4 # 32 Bit
$CPSApp.WinAppObject.DefaultWindowType = 6 # MFWINWindowPercent
$CPSApp.WinAppObject.DefaultWindowScale = 95 # 95%
$CPSApp.WinAppObject.PNAttributes = 8
$CPSApp.WinAppObject.SetIconBitmaps( $CPSReferenceIcon.IconMaskSize, $CPSReferenceIcon.IconMaskBitmap, $CPSReferenceIcon.IconDataSize, $CPSReferenceIcon.IconDataBitmap)
$CPSApp.AddUser( 1, "CDC", 4, "CTX-Admins")
$CPSApp.AddUser( 1, "CDC", 4, "CTX-Support")
$CPSApp.SaveData()
$CPSAppBinding = New-Object -ComObject MetaFrameCOM.MetaFrameAppSrvBinding
$CPSAppBinding.Initialize(6,$ServerName,$CPSApp.DistinguishedName)
if ($CPSAppBinding)
{
Write-Host "Publishing"$CPSApp.BrowserName"on $ServerName" -foregroundcolor Green
$CPSApp.AddServer($CPSAppBinding)
$CPSApp.SaveData()
}
else
{
Write-Host "Unable to create App Binding" -foregroundcolor red
}
}
Publish-Desktop("$env:COMPUTERNAME")
Shown below is the new “script”. As you can see it is actually a one-liner if you take out the function stuff. Also I don’t have the icon issue because it automatically creates the correct icon.
function Publish-Desktop( [string]$ServerName)
{
New-XAApplication -ApplicationType ServerDesktop -DisplayName "$ServerName Desktop" -FolderPath "Applications/Admin/Desktops" -Description "Admin Desktop for Remote Administration" -ClientFolder "Admin\Desktops" -WindowType "95%" -ColorDepth TrueColor -Accounts "$ServerName\Administrators" -Servernames $Servername
}



(6)
(6)
(0)
Comments
Leave a comment Trackback