i have a .ps1 file which fetch folder content from the folder.how to run that .ps1 file from jmeter so i can do performance testing? - powershell

I have a .ps1 file which fetch folder content from the folder. How to run that .ps1 file from jmeter so I can do performance testing?
PS C:\Users\######> D:\KANHA_####\niii1.ps1

Add OS Process Sampler to your Test Plan
Configure it as follows:
Command: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
Argument 1: -File
Argument 2: C:\Users######> D:\KANHA_####\niii1.ps1
That's it, when you run the test JMeter will execute the script and you will be able to see the output using i.e. View Results Tree listener.
More information: How to Run External Commands and Programs Locally and Remotely from JMeter article for more information.
P.S. You might need to amend execution policy settings

Related

WinSCP - Unknown command and '.log' is not recognized as an internal or external command

Context: I'm using powershell to instantiate a batch file to execute the synchronize remote command in WinSCP and pull in fresh data from a remote directory to my local directory. See screenshots below for contents of the WinSCP commands and the batch file contents.
When I try to execute I am able to successfully authenticate but I see 2 errors.
Batch file contents:
winscp.com /script=winscp_commands_ar_history.txt
/log=C:/Users/REDACTED/Desktop/AR_History_Report/winscp_log_ar_history.txt
WinSCP commands:
option batch abort
option confirm off
open sftp://REDACTED:REDACTED#sftp.REDACTED.com
-hostkey="ssh-rsa 2048 cc:ea:2e:03:96:ca:e7:c0:59:74:13:a8:XX:XX:XX:XX"
synchronize remote /export/GroupAccess/REDACTED/Cognos Reporting/CogTest
C:/Users/REDACTED/Desktop/AR_History_Report
exit
Powershell output:
Errors:
Unknown command '-hostkey=ssh-rsa 2048 cc:ea:2e:03:96:ca:e7:c0:59:74:13:a8:XX:XX:XX:XX'.
'/log' is not recognized as an internal or external command,
operable program or batch file.
Question: How do I resolve these 2 errors? I suspect the last one is related to environment variables since it seems powershell didn't recognize the WinSCP log command so I've added WinSCP to my PATH environment variable but I'm still getting the same errors. Can someone please assist? Thank you.
Both your batch file and WinSCP script have line breaks in the middle of commands. Moreover, in the synchronize command you need to wrap the path with spaces to double quotes.
The batch file should be:
winscp.com /script=winscp_commands_ar_history.txt /log=C:/Users/REDACTED/Desktop/AR_History_Report/winscp_log_ar_history.txt
And the script file should be:
option batch abort
option confirm off
open sftp://REDACTED:REDACTED#sftp.REDACTED.com -hostkey="ssh-rsa 2048 cc:ea:2e:03:96:ca:e7:c0:59:74:13:a8:XX:XX:XX:XX"
synchronize remote "/export/GroupAccess/REDACTED/Cognos Reporting/CogTest" C:/Users/REDACTED/Desktop/AR_History_Report
exit
As an aside, as #mklement0 commented, you don't need another powershell process to invoke a batch file from PowerShell - just invoke batch files directly: .\ar_trigger_history.bat

Start-Process : The system cannot find the file specified from TeamCity Build step but works fine locally

i am trying to run Pact broker can i deploy tool with paramaters which is working fine locally but when i add the build step in TeamCity it is throwing below error
Start-Process : This command cannot be run due to the error: The
system cannot find the file specified.
when i run the same powershell script locally, it is working fine .
powershell script:
CanIDeploy.bat code is
Note: the reason i am calling pact-broker.bat from power shell script is, unable to run bat file from Teamcity , that is the reason created powershell script which internally calls pact broker bat file.
any help is appreciated
I see that you use relative path, but what about the working directory? I see a different path in the error message vs what you show where the file is.

Execute jar and display text in jenkins console log

I have abc.jar file to deploy and run in remote machine.
I have transferred the file using jenkins, now what I have done is, call a a.bat batch file on remote machine using psexec in Execute Windows Batch Command.
a.bat executes the abc.jar
When the jar begins execution, the command prompt texts are stored in a file.
using java -jar abc.jar >> a.log 2>&1
Now what I want is to display the a.log contents in the jenkins console when the jar file is being executed
(the file is continuously being written and I want to show it in jenkins console as it is being written)
I have tried to do it using parallel processing by calling start twice, one for calling batch file, another using type for displaying.
But when I use start I get Process leaked file descriptor .
Is there any other way I can achieve this. Be it calling powershell or scheduled task in jenkins.
You need to look for tee equivalents in windows , there are few like GNU utilities for Win32, however if you have cygwin you can still use tee which will easy the prcoess.
Now the wuestion arises how to run my jar file on cygwin from jenkins ?
you can still use execute windows[batch] shell. and add cygwin installation path to the PATH variable and start using linux command like a BOSS.
or you can use powershell tee in built command from batch.

TeamCity running Powershell script, but failing to execute a batch file

I am currently in the process of implementing a deployment method using Teamcity, which runs a Powershell script on my Build Agent, which then configures my Production environment etc.
I have a problem with the Powershell script though, in that it can't seem to run the batch file from it.
The script runs perfectly if I run it manually, it only fails when run via TeamCity.
In the build log I am getting the error:
'myBatchFile.bat' is not recognized as an internal or external command, operable program or batch file.
The batch file and the powershell script are in the same directory and the batch file is called as such:
cmd /c Deploy.bat
I have my TeamCity configuration set up to have the build step for this as:
Script: File
ScriptExecutionMode: Execute script with -File argument
Script Arguments: None
Additional CMD line params: None
I had originally not used the cmd to try to execute the batch file, but executing the batch file like .\Deploy.bat did not seem to work either.
Is there an additional thing I need to set up in order to get the batch file to run? The rest of the script runs fine, just the call to the batch that doesn't.
This is a bit of a wild stab as it's difficult to predict what's happening, but from the description it seems like the path is been altered in the script and it's also dynamic as TeamCity creates temp directories, but if you replace:
cmd /c Deploy.bat
with
cmd /c "$(Split-Path $myinvocation.MyCommand.Path)\Deploy.bat"
then I think this will be able to located the deploy script.
Let me know how it goes.

Run a exe file through a power shell script

I want to run a power shell script which can run a exe file and following are my requirements.
I have that exe file in a remote server location(//ES-WEBSRV01/DBMigration) which is shared to my local machine. Also I want to run that ps file through a cmd.exe.
You can simply call it like any other program:
\\ES-WEBSRV01\DBMigration\something.exe
or, if it contains spaces somewhere along the path:
& "\\ES-WEBSRV01\DBMigration\some thing.exe"
I have no clue what you mean by »Also I want to run that ps file through a cmd.exe.«, though. If you mean that you need a batch file and want to run the PowerShell script from there, then:
powershell -file myscript.ps1