Export apps setting from one delivery group and import to a different delivery group by using PowerShell
Instructions
Export Script:
===========Instruction: please copy the below script snippets as XenAppExport.ps1 and run.
If you have any execution policy please make them exception or unrestricted then run
<#
# File Name : XenAppExport.ps1
# Description:
#
# Exporting Application Data and Icons to XML format. This will allow
# users to import applications and the applications settings in another
# site for testing or site replication.
#>
# Adding Citrix Snapins
Add-PSSnapin Citrix*
# Setting start up location
$Location = $MyInvocation.MyCommand.Path -replace $MyInvocation.MyCommand.Name,"";
set-location $Location;
# Grabs applications
$apps = Get-BrokerApplication -MaxRecordCount 2147483647
$Results = @()
foreach($app in $apps)
{
# Building Properties for each application
$Properties = @{
AdminFolderName = $app.AdminFolderName
AdminFolderUid = $app.AdminFolderUid
ApplicationName = $app.ApplicationName
ApplicationType = $app.ApplicationType
AssociatedDesktopGroupPriorities = $app.AssociatedDesktopGroupPriorities
AssociatedDesktopGroupUUIDs = $app.AssociatedDesktopGroupUUIDs
AssociatedDesktopGroupUids = $app.AssociatedDesktopGroupUids
AssociatedUserFullNames = $app.AssociatedUserFullNames
AssociatedUserNames = $app.AssociatedUserNames
AssociatedUserUPNs = $app.AssociatedUserUPNs
BrowserName = $app.BrowserName
ClientFolder = $app.ClientFolder
CommandLineArguments = $app.CommandLineArguments
CommandLineExecutable = $app.CommandLineExecutable
CpuPriorityLevel = $app.CpuPriorityLevel
Description = $app.Description
Enabled = $app.Enabled
IconFromClient = $app.IconFromClient
EncodedIconData = (Get-Brokericon -Uid $app.IconUid).EncodedIconData # Grabs Icon Image
MetadataKeys = $app.MetadataKeys
MetadataMap = $app.MetadataMap
Name = $app.Name
PublishedName = $app.PublishedName
SecureCmdLineArgumentsEnabled = $app.SecureCmdLineArgumentsEnabled
ShortcutAddedToDesktop = $app.ShortcutAddedToDesktop
ShortcutAddedToStartMenu = $app.ShortcutAddedToStartMenu
StartMenuFolder = $app.StartMenuFolder
UUID = $app.UUID
Uid = $app.Uid
UserFilterEnabled = $app.UserFilterEnabled
Visible = $app.Visible
WaitForPrinterCreation = $app.WaitForPrinterCreation
WorkingDirectory = $app.WorkingDirectory
}
# Stores each Application setting for export
$Results += New-Object psobject -Property $properties
}
# Setting File name with time stamp
$Date = Get-Date
$FileName = $Date.ToShortDateString() + $Date.ToLongTimeString()
$FileName = (($FileName -replace ":","") -replace " ","") -replace "/",""
$FileName = "Apps" + $FileName + ".xml"
# Exporting results
$Results | export-clixml .\$FileName
Import Script :
===========
Instruction: please copy the below script snippets as XenAppImport.ps1 and run.
If you have any execution policy please make them exception or unrestricted then run
<#
# File Name : XenAppImport.ps1
# Description: Importing Application Data and Icons from exported xml file.
#
# Notes : Getting Delivery Group from Arguments
# I.e. .\XenAppImport.ps1 "<Delivery Group Name>" .\<AppExportedXMLFile>.xml
#>
# Adding Citrix Snapins
Add-PSSnapin Citrix*
# Setting start up location
$Location = $MyInvocation.MyCommand.Path -replace $MyInvocation.MyCommand.Name,""
set-location $Location
# Delivery Group for imported location
$dg = Get-BrokerDesktopGroup $args[0]
#Importing Application Data
$apps = Import-Clixml $args[1]
foreach ($app in $apps)
{
#Resetting failure detection
failed = $false
#Publishing Application
Write-Host "Publishing APPLICATON:" $app.PublishedName
if ($app.CommandLineArguments.Length -lt 2) {$app.CommandLineArguments = " "}
#Display Application Settings
write-host -ForegroundColor Cyan "BrowserName : " $app.BrowserName
write-host -ForegroundColor Cyan "ComdLineExe : " $app.CommandLineExecutable
write-host -ForegroundColor Cyan "Description : " $app.Description
write-host -ForegroundColor Cyan "ComdLineArg : " $app.CommandLineArguments
write-host -ForegroundColor Cyan "Enabled : " $app.Enabled
write-host -ForegroundColor Cyan "Name : " $app.Name
write-host -ForegroundColor Cyan "UserFiltEna : " $app.UserFilterEnabled
write-host -ForegroundColor Cyan "WorkingDire : " $app.WorkingDirectory
write-host -ForegroundColor Cyan "Published : " $app.PublishedName
write-host -ForegroundColor Cyan "ClientFolder: " $app.ClientFolder
Try{
#Prep for Application Import - Removing Null values
# * Not just some null value, any null values seems to crash this processes.
# * Application folders screw this field up, had to use PublishedName for -Name property.
$MakeApp = 'New-BrokerApplication -ApplicationType HostedOnDesktop'
if($app.BrowserName -ne $null){$MakeApp += ' -BrowserName $app.BrowserName'}
if($app.CommandLineExecutable -ne $null){$MakeApp += ' -CommandLineExecutable $app.CommandLineExecutable'}
if($app.Description -ne $null){$MakeApp += ' -Description $app.Description'}
if($app.ClientFolder -ne $null){$MakeApp += ' -ClientFolder $app.ClientFolder'}
if($app.CommandLineArguments -ne $null){$MakeApp += ' -CommandLineArguments $app.CommandLineArguments'}
if($app.PublishedName -ne $null){$MakeApp += ' -Name $app.PublishedName'}
if($app.UserFilterEnabled -ne $null){$MakeApp += ' -UserFilterEnabled $app.UserFilterEnabled'}
if($app.Enabled -ne $null){$MakeApp += ' -Enabled $app.Enabled'}
if($dg -ne $null){$MakeApp += ' -DesktopGroup $dg'}
if($app.WorkingDirectory -ne $null){$MakeApp += ' -WorkingDirectory $app.WorkingDirectory'}
if($app.PublishedName -ne $null){$MakeApp += ' -PublishedName $app.PublishedName'}
#Creating Application
Invoke-Expression $MakeApp | Out-Null
}
catch
{
write-host -ForegroundColor Red $_.Exception.Message
write-host -ForegroundColor Red $_.Exception.ItemName
write-host -ForegroundColor Red "Error on " $app.BrowserName
write-host -ForegroundColor Red "Error on " $app.CommandLineExecutable
write-host -ForegroundColor Red "Error on " $app.Description
write-host -ForegroundColor Red "Error on " $app.CommandLineArguments
write-host -ForegroundColor Red "Error on " $app.Enabled
write-host -ForegroundColor Red "Error on " $app.Name
write-host -ForegroundColor Red "Error on " $app.UserFilterEnabled
$failed = $true
}
if($failed -ne $true)
{
#Importing Icon
$IconUid = New-BrokerIcon -EncodedIconData $app.EncodedIconData
#Setting applications icon
Set-BrokerApplication $app.PublishedName -IconUid $IconUid.Uid
write-host -ForegroundColor Green "Working on Icon" $IconUid.Uid "for application:" $app.PublishedName
# Adding Users and Groups to application associations
If($app.AssociatedUserNames -ne $null)
{
Try
{
$users = $app.AssociatedUserNames
foreach($user in $users)
{
write-host -ForegroundColor Yellow "Adding User or Group:" $user "for application:" $app.PublishedName
Add-BrokerUser -Name "$user" -Application $app.PublishedName
}
}
catch
{
write-host -ForegroundColor Red $_.Exception.Message
write-host -ForegroundColor Red $_.Exception.ItemName
write-host -ForegroundColor Red "Error on User " $user "for application:" $app.PublishedName
}
}
}
}