0

How do I execute a powershell script from AutoIt code?

I assume it might be something like:

Runwait(@ComSpec & " /c powershell.exe c:\Mytest.ps1", "", @SW_HIDE)

or

Runwait(powershell.exe c:\Mytest.ps1", "", @SW_HIDE)

But neither of those seem to be working.

1
  • powershell.exe -File C:\MyTest.ps1 (if script execution policy permits). Commented Jan 14, 2017 at 2:59

2 Answers 2

3
Runwait("powershell.exe c:\Mytest.ps1", "", @SW_HIDE)

and right click on au3 file and select 'run script(x64)'

test powershell script that i used:

"heelllo" >> h:\somesome.txt
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, this basically works... when I right click and run as "run script(x64)" it works fine... but when I'm in the SciTE script editor, with the script open, and run the script by pressing "F5"... It doesnt work from there. Any thoughts? I tried running the script editor as administrator in windows but nothing.
-1

I the end, this solution seems to work:

Local $iPID = Run('powershell.exe -executionpolicy bypass -windowstyle hidden -noninteractive -nologo -file C:\MyScript.ps1"', "c:\", @SW_HIDE, $STDOUT_CHILD)
; Wait until the process has closed using the PID returned by Run.
ProcessWaitClose($iPID)
; Read the Stdout stream of the PID returned by Run. 
Local $sOutput = StdoutRead($iPID)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.