The CSV file structure was setup as follows:
BrowserName,DisplayName,WorkerGroupNames,Accounts,CommandLineExecutable,WorkingDirectory,FolderPath,ClientFolder
Example App, Example, Test Worker Group, mshorrosh, C:\windows\system32\notepad.exe, c:\windows\system32\, Applications/Test, Test\
And the script....
# Load the snapins
Add-PSSnapin citrix* -ErrorAction SilentlyContinue
#import the csv file
$apps = Import-Csv C:\apps.csv
#each line in the csv
foreach($app in $apps)
{
#test if workergroup provided exists
try{
$WG = Get-XAWorkerGroup $app.WorkerGroupNames -ErrorAction Stop
} catch {
Write-Host "Error: " $app.BrowserName " resulted in " $_.Exception.Message " please create worker group first"
break
}
#trying to get the executables icon from the CommandLineExecutable
try{
$EncodedIconData = Get-CtxIcon $app.CommandLineExecutable -index 0
} catch [Exception] {
Write-Host "Error: Obtaining the icon failed: " $_.Exception.Message
}
#checking browsername length, found out it has a limit
if($app.BrowserName.length -gt 36)
{
Write-Host "Error: BrowserName for " $app.BrowserName " length is to long, must be less than 36 characters, please correct"
}
else
{
$success = $FALSE
#try to publish new app
try {
$NewApp = New-XAApplication `
-ApplicationType "ServerInstalled" `
-EncodedIconData $EncodedIconData `
-WorkerGroupNames $app.WorkerGroupNames `
-BrowserName $app.BrowserName `
-Enabled $TRUE `
-Accounts $app.Accounts `
-WorkingDirectory $app.WorkingDirectory `
-CommandLineExecutable $app.CommandLineExecutable `
-FolderPath $app.FolderPath `
-ClientFolder $app.ClientFolder `
-WindowType "100%" `
-ColorDepth Colors32Bit `
-InstanceLimit "-1" `
-AddToClientStartMenu $false `
-AnonymousConnectionsAllowed $false `
-DisplayName $app.DisplayName `
-ErrorAction Stop
$success = $TRUE
} catch {
Write-Host "Error: " $_.Exception.Message
} finally {
if($success)
{
Write-Host $app.BrowserName "added successfully."
}
}
}
}