Thursday
Sep202012
LoadRunner - Create ICA Files With Powershell
Thursday, September 20, 2012 at 8:19PM
A recent client engagement required the creation of 1000 Citrix ICA files, each using a different user id. Powershell was used to automate this process.
Step 1 - Obtain An Example ICA File
- Start with an ICA file that works properly.
- Test the ICA file by double clicking to launch the application.
Example ICA File (template.ICA)
[WFClient] Version=2 HttpBrowserAddress=AAAXXML01 HttpBrowserAddress2=AAAXXML02 EnableSSOnThruICAFile=On [ApplicationServers] AppToTest= [AppToTest] Address=AppToTest InitialProgram=#AppToTest ClientAudio=On AudioBandwidthLimit=1 Compress=On TWIMode=On DesiredHRES=1024 DesiredVRES=768 DesiredColor=16 TransportDriver=TCP/IP WinStationDriver=ICA 3.0 BrowserProtocol=HTTPonTCP UseLocalUserAndPassword=On AutoLogonAllowed=On Username=LR0000 Domain=XXXGlobal Password= ClearPassword=password1 EnableSSOnThruICAFile=On SSOnUserSetting=On SSOnCredentialType=Any
Step 2 - Powershell Script Objectives
- Generate multiple ICA files.
- Flexible. Create parameters to allow for customized use.
- Password was not changed, assume all users have the same password (hardcoded in ICA file).
- Result of running will create an ICA directory containing the generated ICA files.
CreateICA.ps1 Contents
# ****************************************************************************** # CreateICA.ica # # Creates ICA files based on a source ICA file. A .dat file is also created # that contains all the user names. # # ------------------------------------------------------------------------------ # Usage (within PowerShell ISE): # # cd# .\CreateICA.ps1 -iterations 400 -startnumber 750 -source template.ICA # -replacetext LR0000 -prefix LR -digits 4 # # Usage (within Command Prompt): # # cd # powershell .\CreateICA.ps1 -iterations 400 -startnumber 750 -source template.ICA # -replacetext LR0000 -prefix LR -digits 4 # # ------------------------------------------------------------------------------ # Creates ICA files by doing the following steps: # # 1. Loop through the given number of iterations and do steps 2-4 for each. # 2. Create the new name of the ICA file by taking the source file name and # appending a number (combination of startnumber and iteration number). # 3. Copy source ICA file to this new ICA file name. # 4. Replace text within the ICA file. # # ------------------------------------------------------------------------------ # Help # # If the script does not run, the ExecutionPolicy might have to be changed. # # Get-ExecutionPolicy # Set-ExecutionPolicy RemoteSigned # ****************************************************************************** # ------------------------------------------------------------------------------ # Parameters used by script. Some are defaulted (if not specified) and others # are required. The required parameters will display a prompt if not given. # ------------------------------------------------------------------------------ param ( [int]$iterations = 1, # Default the number of iterations to 1. [int]$startnumber = 1, # Default the startnumber to 1. [int]$digits = 4, # Default the number of digits to 4. [string]$source = $(Read-Host -prompt "The source ICA file to copy"), [string]$prefix = $(Read-Host -prompt "The user name prefix"), [string]$replacetext = $(Read-Host -prompt "The text to replace in the source file"), [string]$datfile = "citrix_users.dat", # Default file created with user ids. [string]$paramname = "pUserName" # Default parameter name for dat file. ) # ------------------------------------------------------------------------------ # Get the directory of the CreateICA.ps1 script. # ------------------------------------------------------------------------------ $scriptpath = split-path -parent $MyInvocation.MyCommand.Definition cd $scriptpath # ------------------------------------------------------------------------------ # Output the script parameters. # ------------------------------------------------------------------------------ "scriptname = " + $MyInvocation.MyCommand.Name "scriptpath = " + $scriptpath "iterations = " + $iterations "startnumber = " + $startnumber "source = " + $source "replacetext = " + $replacetext "prefix = " + $prefix "digits = " + $digits "datfile = " + $datfile "paramname = " + $paramname # ------------------------------------------------------------------------------ # If the ICA sub-directory does not exist, create it. # ------------------------------------------------------------------------------ if ((Test-Path ICA) -eq $False) { md "ICA" } # ------------------------------------------------------------------------------ # The code below will do the following: # # 1. Create the .dat file to contain the user ids. # 2. Create the ICA file name by combining the source ICA file name with a # formatted sequential number. # 3. Copy the source ICA file to the new ICA file. # 4. Replace the user name text in the ICA file with a unique value. # ------------------------------------------------------------------------------ $split = $source.split(".") $source = $split[0] $format = "{0:D" + $digits + "}" $stream = [System.IO.StreamWriter] ($scriptpath + "\" + $datfile) $stream.WriteLine($paramname) for ($i=0; $i -lt $iterations; $i++) { $uniquepart = $format -f ($i + $startnumber) $newname = $prefix + $uniquepart $newpath = $source + $uniquepart + ".ICA" $newpath = "ICA\" + $newpath Copy-Item ($source + ".ica") $newpath (Get-Content $newpath) | Foreach-Object {$_ -replace $replacetext, $newname} | Set-Content $newpath $stream.WriteLine($newname) "Processed : " + $newpath } $stream.close() # ******************************************************************************
Directory Contents
Moving Forward
- Modify the Powershell script to handle any type of file.
- If the users are not sequential, supply a list of user names to use (instead of calculating).
- Add more error handling to the Powershell script.
Reader Comments (3)
Thanks for sharing this article.
Qtp training Chennai
Thanks for your informative article on software testing. LoadRunner is popular automation software testing tool that used to validate a software application by generating actual load. Further, it gives precise information about a software application or environment. Loadrunner Training in Chennai
Thanks for sharing this information. Java is one of the popular object oriented programming language used for many of the multinational corporation. So learning Java Training in Chennai is really helpful to make a bright future.