Wednesday, December 9, 2015

Citrix Xenapp Create Icons

Add-PSSnapin Citrix*
$Pathtest=Test-Path "servers.csv"
If (!$Pathtest) 
    {
        write-host -ForegroundColor Red "servers.csv file does not exit, create file with users (DOMAIN\USER)"
        Exit
    }
$ServerList = Import-Csv servers.csv -header "Servers"
$PubFolderPath = Read-Host "Enter the path in appcenter (ex:\Applications\FX PrimeVerify\)"
        $ServerListBase = $ServerList[0] -replace "@{servers=",""
        $ServerListBase = $ServerListBase -replace "}",""
#Write-Host -ForegroundColor Yellow $ServerList.Count
write-host "Please select the Env" -ForegroundColor Yellow
write-host "1.PROD" -ForegroundColor Yellow
write-host "2.DR" -ForegroundColor Yellow
write-host "3.DEV" -ForegroundColor Yellow
write-host "4.UAT" -ForegroundColor Yellow
write-host "5.IST" -ForegroundColor Yellow
$AppEnv = Read-Host 
foreach ($Server in $ServerList){
    If ($Server -ne $ServerList[0])
    {
                    $Server = $Server -replace "@{servers=",""
                    $Server = $Server -replace "}",""
        $application=Get-XAApplication -FolderPath $PubFolderPath"\"$ServerListBase | Sort-Object
        foreach($app in $application)
        {
            $FromBrowserName = $app.BrowserName
            $FromDisplayName = $app.DisplayName
            $FromDescription = $app.Description
            $FromCommandLineExecutable = $app.CommandLineExecutable
            $FromWorkingDirectory = $app.WorkingDirectory
            $FromClientFolder = $app.ClientFolder
            If ($AppEnv -eq "1") { 
                $ToDisplayName = $FromDisplayName.Split("_")[0] + "_" + $Server.Substring(($Server.Length-4))
                $ToBrowserName = $FromBrowserName.Split("_")[0] + "_" + $Server.Substring(($Server.Length-4))
                }
            ElseIf ($AppEnv -eq "2") { 
                $ToDisplayName = $FromDisplayName.Split("_")[0] + "_" + $Server.Substring(($Server.Length-4))+ "-DR" 
                $ToBrowserName = $FromBrowserName.Split("_")[0] + "_" + $Server.Substring(($Server.Length-4))+ "-DR" 
                }
            ElseIf ($AppEnv -eq "3") { 
                $ToDisplayName = $FromDisplayName.Split("_")[0] + "_" + $Server.Substring(($Server.Length-4))+ "-DEV" 
                $ToBrowserName = $FromBrowserName.Split("_")[0] + "_" + $Server.Substring(($Server.Length-4))+ "-DEV" 
                }
            Elseif ($AppEnv -eq "4") {
                $ToDisplayName = $FromDisplayName.Split("_")[0] + "_" + $Server.Substring(($Server.Length-4))+ "-UAT" 
                $ToBrowserName = $FromBrowserName.Split("_")[0] + "_" + $Server.Substring(($Server.Length-4))+ "-UAT" 
                }
            Elseif ($AppEnv -eq "5") {
                $ToDisplayName = $FromDisplayName.Split("_")[0] + "_" + $Server.Substring(($Server.Length-4))+ "-IST" 
                $ToBrowserName = $FromBrowserName.Split("_")[0] + "_" + $Server.Substring(($Server.Length-4))+ "-IST" 
                }
            $ToDescription = $FromDescription
            $ToCommandLineExecutable = $FromCommandLineExecutable
            $ToWorkingDirectory = $FromWorkingDirectory
            $ToClientFolder = $FromClientFolder.Replace($ServerListBase,$Server)
            $AccountInfo = get-xaapplicationreport -BrowserName $app.BrowserName | Select-Object Accounts
            #write-host -ForegroundColor Yellow $ToBrowserName
            #write-host -ForegroundColor Yellow $ToDisplayName
            #write-host -ForegroundColor Yellow $ToDescription
            #write-host -ForegroundColor Yellow $ToCommandLineExecutable
            #write-host -ForegroundColor Yellow $ToWorkingDirectory
            #write-host -ForegroundColor Yellow $ToClientFolder
            #write-host -ForegroundColor Yellow $IconData.IconData
                    $CtxIconData = Get-XAApplicationIcon -BrowserName $FromBrowserName
                    $CtxIcon = $CtxIconData.EncodedIconData
            New-XAApplication -ApplicationType "ServerInstalled" -DisplayName $ToDisplayName -FolderPath $PubFolderPath"\"$Server -BrowserName $ToBrowserName -Description $ToDescription -Enabled $True -ColorDepth Colors16Bit -EncodedIconData $CtxIcon -CommandLineExecutable $ToCommandLineExecutable -WorkingDirectory $ToWorkingDirectory -AnonymousConnectionsAllowed $false -AddToClientStartMenu $false -ClientFolder $ToClientFolder -WaitOnPrinterCreation $false
            Add-XAApplicationServer -BrowserName $ToBrowserName -ServerNames $Server
            $AccountInfo = Get-XAAccount -BrowserName $FromBrowserName | Select-object AccountDisplayName
            foreach($Account in $AccountInfo)
                {
                Add-XAApplicationAccount -BrowserName $ToBrowserName -Accounts $Account.AccountDisplayName
                #write-host $Account.AccountDisplayName
                }
            }
        }
    }

No comments:

Post a Comment