<< Back to Script Library

Start ICA Desktop session

This script modifies the default ICA template from ControlUp and launches a session based on that, so that any customization done in the template will be retained here.
This script requires the Citrix Receiver is installed locally and that Direct Desktop Connection is enabled on the target for your user account.
Version: 1.4.5
Created: 2014-04-08
Modified: 2014-04-27
Creator: Zeev Eisenberg
Downloads: 294
The Script Copy Script Copied to clipboard
    Start an ICA session with the target computer
.PARAMETER TargetServer
   The computer that will be the remote session target. - automatically supplied by CU
.PARAMETER Fullscreen
   Go full screen or use the default 1024x768

Credits to: Joel Bennett for the Set-IniValue function

$TargetServer = $args[0]  # address of the target server - name or IP
$FullScreen = $args[1]    # ask "Fullscreen (Yes/No)?"     ^(?i)(yes|y|no|n)$

Function Set-IniValue($inifile,$section,$name,$value)
   $lines = gc $inifile
   $sections = select-string "^\[.*\]" $inifile
   $start,$end = 0,0
   for($l=0; $l -lt $sections.Count; ++$l){
      if($sections[$l].Line.Trim() -eq "[$section]") {
         $start = $sections[$l].LineNumber
         if($l+1 -ge $sections.Count) {
            $end = $lines.length-1;
         } else {
            $end = $sections[$l+1].LineNumber -2
   if($start -and $end) {
      $done = $false
      for($l=$start;$l -le $end;++$l){
         if( $lines[$l] -match "^\s*$name\s*=" ) {
            $lines[$l] = "{0} = {1}" -f $name, $value
            $done = $true
      if(!$done) {
         $output = $lines[0..$start]
         $output += "{0} = {1}" -f $name, $value
         $output += $lines[($start+1)..($lines.Length-1)]
         $lines = $output
   Set-Content $inifile $lines

# let's replace the %CitrixServer% variable everywhere with the actual name and make a copy of the file elsewhere
Get-Content $Env:AppData\ControlUp\TemplateICAFile.ica | ForEach { $_ -Replace ("%CitrixServer%",$TargetServer) } | Set-Content $env:temp\sba-$TargetServer.ica -Encoding ascii

# set color depth and remove the shadow.exe program instruction (since we want a regular desktop)
Set-IniValue $env:temp\sba-$TargetServer.ica $TargetServer DesiredColor 24
Set-IniValue $env:temp\sba-$TargetServer.ica $TargetServer InitialProgram

If ($FullScreen -match "y")
    Set-IniValue $env:temp\sba-$TargetServer.ica $TargetServer DesiredHRes ([System.Int32]::MaxValue)
    Set-IniValue $env:temp\sba-$TargetServer.ica $TargetServer DesiredVRes ([System.Int32]::MaxValue)
} Else {
    Set-IniValue $env:temp\sba-$TargetServer.ica $TargetServer DesiredHRes 1024
    Set-IniValue $env:temp\sba-$TargetServer.ica $TargetServer DesiredVRes 768

# we're assuming that the .ica extension is associated with the Citrix Receiver here, and Windows
# will automatically start the proper program
Start-Process $env:temp\sba-$TargetServer.ica