Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2569
  • Last Modified:

PowerShell to test ICA connectivity

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
hchabria
Asked:
hchabria
1 Solution
 
Raheman M. AbdulCommented:
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
 
hchabriaAuthor Commented:
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
 
Raheman M. AbdulCommented:
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
New Tabletop Appliances Blow Competitors Away!

WatchGuard’s new T15, T35 and T55 tabletop UTMs provide the highest-performing security inspection in their class, allowing users at small offices, home offices and distributed enterprises to experience blazing-fast Internet speeds without sacrificing enterprise-grade security.

 
hchabriaAuthor Commented:
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
 
Raheman M. AbdulCommented:
Try removing [int] and see if it works
1
 
hchabriaAuthor Commented:
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
 
joharderCommented:
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
 
hchabriaAuthor Commented:
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
 
Member_2_6479323Commented:
Thanks a lot. The script mentioned above (after removing the Int) works perfectly.
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now