Forum Discussion

jkrolczyk's avatar
jkrolczyk
New Contributor
20 days ago

How to run a powershell script from TestComplete with parameters ?

Maybe I am missing this in the documentation? Running PowerShell Scripts From TestComplete | TestComplete Documentation If possible, I was trying to find the syntax to go by for passing in single o...
  • jkrolczy's avatar
    jkrolczy
    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