Jump to content
Welcome to our new Citrix community!
  • 0

Citrix Powershell New-BrokerApplication with AssociatedUserNames


Tom Swift

Question

We’ve been working on an automation project to create several hundred applications using Powershell in Citrix XenApp 1912 and are running in to an issue with a field named “AssociatedUserNames” which we’d like to use to limit visibility to the application so that only a specific Active Directory security group is assigned to the application.

 

In the example below we did a Get-brokerapplication -name "MicroApp\Demo\Maintenance” to display properties of an existing application and you can see that AssociatedUserNames is {DOMAIN\MMDemo_Group}.  We haven’t figured out how to apply this correctly using New-BrokerApplication.  Hoping someone here may have experience with it.

 

Kind Regards,

Tom

 

 

 

 

# Create the new Broker Application (with all ok)

New-BrokerApplication -Name $BA_Name -AdminFolder $BA_AdminFolderName -ApplicationGroup "$BA_ApplicationGroup" -ApplicationType $BA_ApplicationType -BrowserName $BA_Name -CommandLineArguments "$BA_CommandLineArguments" -CommandLineExecutable "$BA_CommandLineExecutable" -WorkingDirectory "$BA_WorkingDirectory" -ErrorVariable chkerror

 

 

Get-brokerapplication -name "MicroApp\Demo\Maintenance"

 

 

AdminFolderName                  : MicroApp\Demo\

AdminFolderUid                   : 5

AllAssociatedDesktopGroupUUIDs   : {f4078b70-9a07-49e7-b56c-eee6e08db3a3}

AllAssociatedDesktopGroupUids    : {6}

ApplicationName                  : Maintenance

ApplicationType                  : HostedOnDesktop

AssociatedApplicationGroupUUIDs  : {}

AssociatedApplicationGroupUids   : {}

AssociatedDesktopGroupPriorities : {0}

AssociatedDesktopGroupUUIDs      : {f4078b70-9a07-49e7-b56c-eee6e08db3a3}

AssociatedDesktopGroupUids       : {6}

AssociatedUserFullNames          : {MMDemo_Group}

AssociatedUserNames              : {DOMAIN\MMDemo_Group}

AssociatedUserSIDs               : {S-1-5-21-3770370002-3746174565-3102094679-1141}

AssociatedUserUPNs               : {}

BrowserName                      : Maintenance_1-1

ClientFolder                     : 

CommandLineArguments             : C:\ProgramData\MicroApp\Maintenance\MMMAINTENANCE.accde /Runtime

CommandLineExecutable            : C:\Program Files (x86)\Microsoft Office\root\Office16\MSACCESS.EXE

ConfigurationSlotUids            : {}

CpuPriorityLevel                 : Normal

Description                      : 

Enabled                          : True

HomeZoneName                     : 

HomeZoneOnly                     : False

HomeZoneUid                      : 

IconFromClient                   : False

IconUid                          : 3

IgnoreUserHomeZone               : False

LocalLaunchDisabled              : False

MachineConfigurationNames        : {}

MachineConfigurationUids         : {}

MaxPerMachineInstances           : 0

MaxPerUserInstances              : 0

MaxTotalInstances                : 0

MetadataKeys                     : {}

MetadataMap                      : {}

Name                             : MicroApp\Demo\Maintenance

PublishedName                    : Maintenance

SecureCmdLineArgumentsEnabled    : True

ShortcutAddedToDesktop           : False

ShortcutAddedToStartMenu         : False

StartMenuFolder                  : 

Tags                             : {}

UUID                             : de79de4a-e0e5-4213-a194-506ca9ddd223

Uid                              : 21

UserFilterEnabled                : True

Visible                          : True

WaitForPrinterCreation           : False

WorkingDirectory                 : C:\Program Files (x86)\Microsoft Office\root\Office16

Link to comment

2 answers to this question

Recommended Posts

  • 0

Including my script to duplicate Apps between to sites. It will create the new apps with proper users, but it may not exactly answer your question about how to create the properties, but maybe will point you in the right direction.

 

############################################################################
# VARIABLE DEFINITIONS
############################################################################
$global:FROMAdminAddress = '<dcFromFQDN>:80'
$global:TOAdminAddress = '<dcToFQDN>:80'

############################################################################
# FUNCTION DEFINITIONS
############################################################################

function Verify-Snapins
{
$LoadedSnapins = Get-PSSnapin -Name *citrix* -ErrorAction SilentlyContinue | Select-Object Name
If($LoadedSnapins.Name -contains 'Citrix.Broker.Admin.V2')
    {
    Write-Host "Successfully verified that necessary Citrix components are loaded in PowerShell" -ForegroundColor Yellow
    }
Else
    {
    $RegisteredSnapins = Get-PSSnapin -Name *citrix* -Registered | Select-Object Name
    If($RegisteredSnapins.Name -contains 'Citrix.Broker.Admin.V2')
        {
        Write-Host "Citrix components are not currently loaded in to PowerShell. Attempting to load components." -ForegroundColor DarkYellow
        Add-PSSnapin *citrix*
        Verify-Snapins
        }
    Else
        {
        Read-Host "The necessary Citrix components to execute this script are not installed on this computer. Press enter to exit."
        Exit
        }
    }
}

function Reset-Script
{
$Message = "Operation completed."
$Question = "Do you want to exit or start over?"

$choices = New-Object Collections.ObjectModel.Collection[Management.Automation.Host.ChoiceDescription]
$choices.Add((New-Object Management.Automation.Host.ChoiceDescription -ArgumentList '&StartOver'))
$choices.Add((New-Object Management.Automation.Host.ChoiceDescription -ArgumentList '&Exit'))

$decision = $Host.UI.PromptForChoice($message, $question, $choices, 1)
if ($decision -eq 0) 
    {
    Write-Host 'Starting over!' -ForegroundColor Yellow
    Start-Script
    } 
else 
    {
    Write-Host 'Exiting!' -ForegroundColor Yellow
    Exit
    }
}

function Select-DeliveryGroup
{
    $DeliveryGroups = (Get-BrokerDesktopGroup -AdminAddress $global:FROMAdminAddress).Name
    $i=1
    Write-Host "Please choose a customer Delivery Group to migrate applications for:" -ForegroundColor Yellow
    ForEach($DeliveryGroup in $DeliveryGroups)
        {
        Write-Host "$i. $DeliveryGroup"
        $i++
        }
    [int]$Choice = Read-Host 'Enter the number for the delivery group to choose'
    $global:DeliveryGroupChoice=$DeliveryGroups[$choice-1]
    Write-Host "$($global:DeliveryGroupChoice) was selected as the Delivery Group." -ForegroundColor Yellow
}

function Export-Apps
{
    # Setting start up location
    $Location = $MyInvocation.MyCommand.Path -replace $MyInvocation.MyCommand.Name,"";
    set-location $Location;

    # Grabs applications
    #$apps = Get-BrokerApplication -MaxRecordCount 2147483647
    $apps =  Get-BrokerApplication -AdminAddress $global:FROMAdminAddress -DesktopGroupUid (Get-BrokerDesktopGroup -AdminAddress $global:FROMAdminAddress -Name $global:DeliveryGroupChoice).Uid -MaxRecordCount 2147483647

    $global: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 -AdminAddress $global:FROMAdminAddress -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
        }
 #       $app | gm
 #       write-host $app.AdminFolderName -ForegroundColor Red
 #       break
        # Stores each Application setting for export
        $global: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
    $global:Results | export-clixml .\$FileName   

    #>
}

function Import-Apps
{
    # Importing applications and associating icons with applications 
    # Setting Delivery Group
    $dg = $global:DeliveryGroupChoice
 
    # Importing Application Data
    # Set the path to your .xml
    $apps = $global:Results
 
    foreach ($app in $apps)
    {
        
        Write-Host "Working on Application: " $app.Name -ForegroundColor Green
       
        If ((Get-Brokerapplication -Name $app.Name -AdminAddress $global:TOAdminAddress -ErrorAction Ignore).Count)
        {

        #Do Not attempt to recreate the application, just use the existing one and add the Delivery Group to it
            Write-Host "Adding Application - Not creating new"
            Try
            {
                Add-BrokerApplication -AdminAddress $global:TOAdminAddress -Name $app.PublishedName -DesktopGroup $global:DeliveryGroupChoice | Out-Null
            }
            Catch
            {
                Add-BrokerApplication -AdminAddress $global:TOAdminAddress -Name $app.Name -DesktopGroup $global:DeliveryGroupChoice | Out-Null
            }
        } else {
        If ($app.AdminFolderName -ne $null -and (Get-BrokerAdminFolder -Name $app.AdminFolderName -AdminAddress $global:TOAdminAddress -ErrorAction Ignore).Count -eq 0) 
        {
            $adminFolder = $app.AdminFolderName.Split("\")
            $folderpath = ""
            $fproot = ""
            foreach ($folder in $adminFolder) 
            {
                if ($folder -ne "")
                {
                    $folderpath += $folder + "\"
                    if ((Get-BrokerAdminFolder -Name $folderpath -AdminAddress $global:TOAdminAddress -ErrorAction Ignore).Count -eq 0)
                    {
                        If ($fproot -ne "") 
                        {
                            New-BrokerAdminFolder -FolderName $folder -ParentFolder $fproot -AdminAddress $global:TOAdminAddress
                        } else {
                            New-BrokerAdminFolder -FolderName $folder -AdminAddress $global:TOAdminAddress
                        }
                    }
                    $fproot = $folder
                }
            }
        }
           #Importing Icon 
          # write-host "Doing Icon - New-BrokerIcon -AdminAddress $global:TOAdminAddress"
           $IconUid = New-BrokerIcon -AdminAddress $global:TOAdminAddress -EncodedIconData $app.EncodedIconData
           $DoIcon = $true

           #Creating New Application

           #If the BrowserName already exists, modify to something that doesn't...
           If((Get-BrokerApplication -BrowserName $app.BrowserName).Count) {
             $unique = $False
             $counter = 0
             
             Do {
                $counter += 1
                $BNTemp = $app.BrowserName + $counter
                If(!(Get-BrokerApplication -BrowserName $BNTemp).Count) {
                    $app.BrowserName = $BNTemp
                    $unique = $True
                }
             }
             Until ($unique)
           }


           #Create the new Application
            Try
            {
                if ($app.CommandLineArguments.Length -lt 2) {$app.CommandLineArguments = " "} 
                #Adding Application
            

                write-host "AdminFolder" $app.AdminFolderName
                write-host "BrowserName" $app.BrowserName
                write-host "ComdLineExe" $app.CommandLineExecutable
                write-host "ClientFldr " $app.ClientFolder
                write-host "Description" $app.Description
                write-host "ComdLineArg" $app.CommandLineArguments
                write-host "Enabled    " $app.Enabled
                write-host "Name       " $app.Name
                write-host "UserFiltEna" $app.UserFilterEnabled
                write-host "WorkingDire" $app.WorkingDirectory
                write-host "Published  " $app.PublishedName

###Comment this out if first attempt fails and use alternate attempt

#<#             
                If($app.ClientFolder -ne $null)
                {
                $appClientFolder = $app.ClientFolder
                #write-host New-BrokerApplication -AdminAddress $global:TOAdminAddress -AdminFolder $app.AdminFolderName -ApplicationType $app.ApplicationType -BrowserName $app.BrowserName -CommandLineExecutable $app.CommandLineExecutable -Description $app.Description -ClientFolder $app.ClientFolder -CommandLineArguments $app.CommandLineArguments -Enabled $app.Enabled -Name $app.PublishedName -UserFilterEnabled $app.UserFilterEnabled -DesktopGroup $dg -WorkingDirectory $app.WorkingDirectory -PublishedName $app.PublishedName | Out-Null
                } else {
                $appClientFolder = "\"
                #write-host New-BrokerApplication -AdminAddress $global:TOAdminAddress -AdminFolder $app.AdminFolderName -ApplicationType $app.ApplicationType -BrowserName $app.BrowserName -CommandLineExecutable $app.CommandLineExecutable -Description $app.Description -ClientFolder $app.ClientFolder -CommandLineArguments $app.CommandLineArguments -Enabled $app.Enabled -Name $app.PublishedName -UserFilterEnabled $app.UserFilterEnabled -DesktopGroup $dg -WorkingDirectory $app.WorkingDirectory -PublishedName $app.PublishedName | Out-Null
                }
                New-BrokerApplication -AdminFolder $app.AdminFolderName -ApplicationType $app.ApplicationType -BrowserName $app.BrowserName -CommandLineExecutable $app.CommandLineExecutable -Description $app.Description -ClientFolder $appClientFolder -CommandLineArguments $app.CommandLineArguments -Enabled $app.Enabled -Name $app.PublishedName -UserFilterEnabled $app.UserFilterEnabled -DesktopGroup $dg -WorkingDirectory $app.WorkingDirectory -PublishedName $app.PublishedName | Out-Null

#>


<#
### Use this if the first attempt fails to properly create all applications

                $MakeApp = 'New-BrokerApplication -AdminAddress $global:TOAdminAddress -ApplicationType $app.ApplicationType'
                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'}

                Invoke-Expression $MakeApp | Out-Null
#>
            }
            Catch
            {
                write-host $_.Exception.Message
                write-host $_.Exception.ItemName
                write-host "Error on "  $app.BrowserName
                write-host "Error on "  $app.CommandLineExecutable
                write-host "Error on "  $app.Description
                write-host "Error on "  $app.CommandLineArguments
                write-host "Error on "  $app.Enabled
                write-host "Error on "  $app.Name
                write-host "Error on "  $app.UserFilterEnabled
            }
            
                #Setting applications icon  
            #     write-host "Doing - Set-BrokerApplication -AdminAddress $global:TOAdminAddress app.Name -IconUid IconUid.Uid"
            If($DoIcon) {
                Try
                {
                   Set-BrokerApplication -Name $app.Name -AdminAddress $global:TOAdminAddress -IconUid $IconUid.Uid | Out-Null
                }
                Catch
                {
                   Set-BrokerApplication -Name $app.PublishedName -AdminAddress $global:TOAdminAddress -IconUid $IconUid.Uid | Out-Null
                }
                   write-host "Working on Icon" $IconUid.Uid
            }
 
            # Adding User Associations
            If($app.AssociatedUserNames -ne $null) 
            {
                Try
                {
                    $users = $app.AssociatedUserNames
 
                    foreach($user in $users)
                    {
                        Try
                        {
                              Add-BrokerUser -AdminAddress $global:TOAdminAddress -Name "$user" -Application $app.Name | Out-Null
                        }
                        Catch
                        {
                              Add-BrokerUser -AdminAddress $global:TOAdminAddress -Name "$user" -Application $app.PublishedName | Out-Null
                        }
                    }
                }
                Catch
                {
                    write-host $_.Exception.Message
                    write-host $_.Exception.ItemName
                    write-host "Error on User  "  $user  $app.Name
                }
            }
        }
    }
 
}
function Start-Script
{
    Write-Host "We will perform the following: Select customer Delivery Group. Then export the apps for that group and import them into Atlanta Environment." -ForegroundColor Yellow
    Select-DeliveryGroup
    Export-Apps
    Import-Apps
}

############################################################################
# SCRIPT EXECUTION BLOCK
############################################################################

Write-Host "Welcome to the ProCirrus application provisioning tool for XenApp 7.6" -ForegroundColor Yellow
Verify-Snapins
Read-Host "Press enter to begin. Hit CTRL-C at any time to cancel the current operation and exit the script."
Start-Script

 

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...