Solved

PowerShell to test ICA connectivity

Posted on 2014-01-22
9
2,105 Views
1 Endorsement
Last Modified: 2016-06-09
I want to check ICA connectivity with the XenApp 6 servers using PowerShell.

I have created .ica file for each server and want PowerShell to execute each .ica file in background with my saved username and password and log the result.

For example, we have two XenApp 6 servers.
XEN-1
XEN-2

I created two .ica files for each of the servers -
Notepad_XEN-1
Notepad_XEN-2

Is it possible to create a PowerShell script that will launch these two .ica files with my username and password in the background and store the result in a log file. The result should be like below-

Notepad_XEN-1 - Launched
Notepad_XEN-2 - Error
1
Comment
Question by:hchabria
9 Comments
 
LVL 18

Expert Comment

by:Raheman M. Abdul
ID: 39799816
Try this: replace the following with your details:
TestUser01    --- your username
MyUsersPassword   ---- your password
DOM --- your domain

The result files are stored in c:\XEN1_....txt
Run in powershell the following:
Replace the exact location of ICA Client on your machine. Open Powershell x86 (32bit version )

-----------------------
[System.Reflection.Assembly]::LoadFile("C:\Program Files (x86)\Citrix\ICA Client\WfIcaLib.dll")
$ICA = New-Object WFICALib.ICAClientClass
$ICA.Address = "Notepad_XEN-1"
$ICA.Username = "TestUser01"
$ICA.SetProp("Password","MyUsersPassword")
$ICA.Domain = "DOM"
$ICA.Application = ""
$ICA.Launch = $true
$ICA.OutputMode = [WFICALib.OutputMode]::OutputModeNormal
$ICA.DesiredHRes = 1024
$ICA.DesiredVRes = 768
$ICA.DesiredColor = [WFICALib.ICAColorDepth]::Color16bit
Register-ObjectEvent -InputObject $ICA -EventName OnConnectFailed -Action {  "$ICA.Address : Connection failed..." | Add-content c:\XEN1_failed.txt }
Register-ObjectEvent -InputObject $ICA -EventName OnLogonFailed -Action {  "$ICA.Address : Logon failed... | add-content c:\XEN1_failed.txt" }
Register-ObjectEvent -InputObject $ICA -EventName OnLogon -Action { "$ICA.Address :   User has logged on..." | add-content c:\XEN1_launched.txt}
$ICA.Connect()
0
 

Author Comment

by:hchabria
ID: 39800259
Thanks for the script. However, it is providing error at the time of launching the .ica file (screenshot attached).
Script ErrorOne thing I should mention that in our environment we have to accept the company provided security message that pops up before launching any of the published applications (screenshot attached).
Security MessagePlease help.
0
 
LVL 18

Accepted Solution

by:
Raheman M. Abdul earned 500 total points
ID: 39800939
The error was because of the input required to launch.
Alternatively:
This might help in your case without opening the session. See if this works. Once you are ok with the output we can direct the output to a file as required in the question.

Refer: http://www.efferen.nl/2012/06/script-check-ica-listener-response/
0
 

Author Comment

by:hchabria
ID: 39802758
Thanks for the link. It can also fulfill my requirement as I just want to check whether the ICA connection with the XenApp servers are Okay or not.

However, I am facing problem with the script. I am getting the below error while running the script. As I am not that much expert in PowerShell can you please help me out to resolve this error?
Script ErrorI am providing the full script also.
###########################################################################
#
# NAME: 	Test-ICA.ps1
#
# AUTHOR:  	Leon van Efferen
#
# E-MAIL:	leon@efferen.nl
#
# COMMENT: 	Test ICA port for correct response.
#
# VERSION HISTORY:
# 1.0 4-7-2012 - Initial release
#
###########################################################################
param(
    [string] $ComputerName = "",
    [int] $port = 1494
   )
 
[string] $output = ""

## Read output from a remote host
function GetOutput
{
  ## Create a buffer to receive the response
  $buffer = new-object System.Byte[] 1024
  $encoding = new-object System.Text.AsciiEncoding
 
  $outputBuffer = ""
  $foundMore = $false
 
  ## Read all the data available from the stream, writing it to the
  ## output buffer when done.
  do
  {
    ## Allow data to buffer for a bit
    #start-sleep -m 100
 
    ## Read what data is available
    $foundmore = $false
    $stream.ReadTimeout = 250
 
    do
    {
      try
      {
        $read = $stream.Read($buffer, 0, 1024)
 
        if($read -gt 0)
        {
          $foundmore = $true
          $outputBuffer += ($encoding.GetString($buffer, 0, $read))
        }
      } catch { $foundMore = $false; $read = 0 }
    } while($read -gt 0)
  } while($foundmore)
 
  $outputBuffer
}
 

  ## Open the socket, and connect to the computer on the specified port

  #write-host "Connecting to $ComputerName on port $port"
 
  trap { Write-Error "Could not connect to remote computer: $_"; exit }
  $socket = new-object System.Net.Sockets.TcpClient($ComputerName, $port)
  $stream = $socket.GetStream()
  $writer = new-object System.IO.StreamWriter $stream

    ## Receive the output that has buffered so far
    $SCRIPT:output += GetOutput
                
 
 
  ## Close the streams
  $writer.Close()
  $stream.Close()
 
if ($output -match "ICA") {$result = "Success"}
Else {$result = "Failed"} 
$obj = new-object psobject
$obj | add-member noteproperty ComputerName ($ComputerName)
$obj | add-member noteproperty Status ($result)
$obj | add-member noteproperty Output ($output)
$obj

Open in new window

1
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
LVL 18

Expert Comment

by:Raheman M. Abdul
ID: 39802817
Try removing [int] and see if it works
1
 

Author Comment

by:hchabria
ID: 39806458
Thanks so much. After removing [int] it's working fine.

I am using following command to test ICA for multiple servers and it's working fine.

Get-Content C:\Servers.txt |% {.\Test-ICA.ps1 -ComputerName $_ -TimeOut } | Out-File C:\ICAResult.txt

How can I run this command through batch file?
1
 
LVL 15

Expert Comment

by:joharder
ID: 39814075
There's a couple of really easy ways to do this with EdgeSight.  If you enable Active Application Monitoring, you can test synthetic app launches.  Or, within XenApp, if you set up Health Monitoring within your XenApp farm (the default install only provides 4 tests), you can see the output from the ICA test within EdgeSight.
0
 

Author Comment

by:hchabria
ID: 39829201
Though we have EdgeSight, we don't have Active Application Monitoring installed.

We have already configured Health Monitoring for all XenApp servers but how do we check the ICA test withing EdgeSight? Can you please let me know the steps?
0
 

Expert Comment

by:Member_2_6479323
ID: 41645659
Thanks a lot. The script mentioned above (after removing the Int) works perfectly.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

#Citrix #XenApp #Citrix Scout #Citrix Insight Services #Microsoft VMMAP #Microsoft ADEXPLORE #Microsoft RAMMAP #Microsoft TCPVIEW #Microsoft AUTORUNS #Microsoft PROCESS EXPLORER #Microsoft PROCESS MONITOR
If your vDisk VHD file gets deleted from the image store accidentally or on purpose, you won't be able to remove the vDisk from the PVS console. There is a known workaround that is solid.
How to install and configure Citrix XenApp 6.5 - Part 1. In this video tutorial we have explained step by step installation of Citrix XenApp 6.5 Server on Windows Server 2008 R2 is explained in this video. We have explained the difference between…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

28 Experts available now in Live!

Get 1:1 Help Now