Solved

PowerShell to test ICA connectivity

Posted on 2014-01-22
9
2,029 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 18

Expert Comment

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

Author Comment

by:hchabria
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks a lot. The script mentioned above (after removing the Int) works perfectly.
0

Featured Post

Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

Join & Write a Comment

Microsoft Windows Server Update Service (WSUS) is free for everyone, but it lacks of some desirable features like send an e-mail to the administrator with the status of all computers on the WSUS server. This article is based on my PowerShell script …
Create and license users in Office 365 in bulk based on a CSV file. A step-by-step guide with PowerShell script examples.
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.

762 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

9 Experts available now in Live!

Get 1:1 Help Now