Jump to content

Run powershell script with AutoIt


Recommended Posts

If I manually open CMD (admin or not, same result) and run: Powershell.exe -executionpolicy Bypass -File  "C:\Users\dml.admin\Desktop\Test\PSScript.ps1"

Then it works.

When I right-click the ps1 script and choose "Run with Powershell", then it also works.

Edited by david1337
Link to comment
Share on other sites

  • Developers

Could it be an x86/x64 issue since it works with the batchfile from the CMD prompt? 
Have you tried running the script in x64?
Have you tried running the batch file from AutoIt3?

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

  • 5 months later...

check this Thread.  

you need to download the Com objects Sapien , but they are free. install the Package.  play with the code and you should be fine. i'm using it in some of my scripts, its a bit limited, but if all the work can be done in your PS1 script and read by autoit, 

 

regards,

T

 

 

Edited by Cirusnb
fixed text
Link to comment
Share on other sites

  • 2 years later...

Ok guys I'am not used to revive old topics, but I have found very useful this thread so to summarize :

HOW TO LAUNCH POWERSHELL FILES.PS1 FROM AUTOIT.

  1. if compiling 32 bit and run in 64 bit system please add on top  to your script, (otherwise compiled 64bit it is not needed.)
    #include <WinAPIFiles.au3>
    
    _WinAPI_Wow64EnableWow64FsRedirection(False)
  2. the command line has to be like this:
    ShellExecuteWait('PowerShell.exe', '-executionpolicy Bypass -File "' & $newPSfile & '"')

    where $newPSfile is the complete path of your file.ps1 (you decide shellexecuteWAIT or not wait)

  3. in your PC or server launch AS admnistrator the autoitscript

Done

 

Thank you all!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...