Forum Discussion

sjames's avatar
sjames
New Contributor
7 years ago

power shell scripts not running as expected using testcomplete script

Hello All,

 

My requirement:

1. get version number of installed app under test before the test starts.

am using a powershell script for this.

Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* | Select-Object DisplayName, DisplayVersion |
Where-Object {$_.DisplayName -Like 'myapp*'}

 

2. There will be different versions to be installed so I would like to create a txt file from above script

 

Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* | Select-Object DisplayName, DisplayVersion |
Where-Object {$_.DisplayName -Like 'myapp*'} > path\to\txt\myApp.txt

 

 

I have power shell script to update a text file which is supposed run from testcomplete. Manually ps1 script works but not from script;

my script looks like;

Sys.OleObject("WScript.Shell").Run("PowerShell -File " + ".\myScript.ps1");

 

myScript.ps1 script is as follows;

 


$MyReport= "version_info.txt"
$scriptPath = split-path -parent $MyInvocation.MyCommand.Definition
$Folder= Join-Path $scriptPath $MyReport

 

# get items from system that has name myapp

Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* | Select-Object DisplayName, DisplayVersion |
Where-Object {$_.DisplayName -Like 'myapp*'} > $Folder

 

the powershell is working and successfully executed (it seems - no errors) but my text file created but not updated. It is updated if run powershell script manually! why testcomplete cannot???

 

Any thoughts?

 

S

  • Hi Nis,

    That's the issue, I have not getting any error message and power shell window just open and closed. Seems working but not getting expected results.

    I have somehow resolved the issue by adding CLR Bridge > browse GAC > added system.management.Automation and below script, now seems working!!

    var powerShellScript = "AppVersion.ps1"; // script is in the original message

    function getVersionOfInstalledAppUnderTest()

     

    {

      var currentDirectory = aqFileSystem.GetCurrentFolder();

      psScriptPath = currentDirectory + "\\" + powerShellScript;

      var PowerShell = dotNET.System_Management_Automation.PowerShell.Create();

      PowerShell.AddScript(currentDirectory + "\\" + powerShellScript);

     // invoke powershell to get the results

     var results = PowerShell.Invoke();

     

    }

     

  • sjames's avatar
    sjames
    New Contributor

    Hi Nis,

    That's the issue, I have not getting any error message and power shell window just open and closed. Seems working but not getting expected results.

    I have somehow resolved the issue by adding CLR Bridge > browse GAC > added system.management.Automation and below script, now seems working!!

    var powerShellScript = "AppVersion.ps1"; // script is in the original message

    function getVersionOfInstalledAppUnderTest()

     

    {

      var currentDirectory = aqFileSystem.GetCurrentFolder();

      psScriptPath = currentDirectory + "\\" + powerShellScript;

      var PowerShell = dotNET.System_Management_Automation.PowerShell.Create();

      PowerShell.AddScript(currentDirectory + "\\" + powerShellScript);

     // invoke powershell to get the results

     var results = PowerShell.Invoke();

     

    }

     

  • NisHera's avatar
    NisHera
    Valued Contributor

    do you run test-complete as administrator?

    what error message do you get?