Solved

PowerShell to test ICA connectivity

Posted on 2014-01-22
9
2,350 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
9 Comments
 
LVL 19

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 19

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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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
 
LVL 19

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 AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
What if you have to shut down the entire Citrix infrastructure for hardware maintenance, software upgrades or "the unknown"? I developed this plan for "the unknown" and hope that it helps you as well. This article explains how to properly shut down …
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.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

623 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