How to run a powershell script from TestComplete with parameters ?
- 20 days ago
function Test()
{
// Create a WshShell object
var WshShell = new ActiveXObject("WScript.Shell");
// Path to your PowerShell script
var scriptPath = "C:\\qTestReport\MyScript.ps1";// Parameters to pass to the script
var param1 = "Bob";
var param2 = "12";// Construct the command line string
var command = "powershell -File \"" + scriptPath + "\" " + param1 + " " + param2;
Log.Message(command);// Execute the PowerShell script with parameters
WshShell.Run(command, 0, true);
}MyScript.ps1
param
(
[string]$Name,
[int]$Age
)$jsonBody = "C:\qTestReport\ESP\qTestResults\finalBody.txt"
Write-Output "Hello, $Name! You are $Age years old."
$Name | Out-File -FilePath $jsonBody
Add-Content -Path $jsonBody $Age
But file is not getting generated with passed in values