Forum Discussion

carles_roch-cun's avatar
carles_roch-cun
New Contributor
7 years ago

Can not execute PowerShell scripts from TestComplete

I am running TestComple12 as administrator (RunAs). The code is developed in VB. From my TC code  I invoke a PowerShell script, using the following command 

 

 

      Call Sys.OleObject("WScript.Shell").Run("powershell -file C:\Temp\borrar\DeleteScheduledJob.ps1")

 

I use this command after the article found at https://support.smartbear.com/testcomplete/docs/testing-with/advanced/using-external-functions/running-powershell-scripts.html

 

The PowerShell script itself is pretty simple

 

     schtasks /delete /tn "Schneider Electric\EDC\EDC-My_Test_Job" /f

 

and runs well when invoked from the PS command line, but not when invoking it from TestComplete

 

I have used variation of this script, to self-elevate its permissions

 

    if (!([Security.Principal.WindowsPrincipal]          [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator"))

    { Start-Process powershell.exe "-NoProfile -ExecutionPolicy Bypass -File `"$PSCommandPath`"" -Verb RunAs; exit }


    schtasks /delete /tn "Schneider Electric\EDC\EDC-My_Test_Job" /f

 

 

With no luck.

 

Any idea why it is not working? I do not get any feedback error from TestComplete, so do not know if the problem is in my code or in TestComplete.

 

Notes:

The scripts were working as expected in W2008, but do not work in my Win10 environment

The Powershell execution policy in the machine is set to Unrestricted

 

Thanks