Jump to content

Powershell In AutoIT


Recommended Posts

Hi Guys,

I have had a look through the various threads talking about powershell but am struggling to get my script to launch properly.

I intend to have a serious of combo selection boxes populated from an INI file and then when a user hits the "launch" button it uses the selected options to launch the powershell script with those parameters.

This line works great from a command prompt:

C:\windows\system32\WindowsPowerShell\v1.0\PowerShell.exe -noexit -STA -Command "& 'C:\Program Files\ApplicaionDir\TAME\HRMenu\Start\Start.ps1' -engine Server01.domain.local -session TAME_TEST -stage DEV -useCredential 'Server01\'"

Iv tried running it as a single line but that doesnt seem to work for me as it doesnt seem to pass through properly. Iv resorted to using it as a group of variables so i can check the command is passed correctly:

$start = '"C:\Windows\System32\windowspowershell\v1.0\powershell.exe" -noexit -STA -Command'

$middle = '"C:\Program Files\ApplicationDir\TAME\HRMenu\Start\Start.ps1"'

$end = '-engine Server01.domain.local -session TAME_TEST -stage DEV -useCredential "Server01\"'

ConsoleWrite(@ComSpec & ' /c ' & $start & ' ' & $middle & ' ' & $end)

Run(@ComSpec & ' /c ' & $start & ' ' & $middle & ' ' & $end, @SystemDir, @SW_HIDE)

The console write above looks correct but the run command doesnt run.

Can anyone help me correct it? (I am assuming the quotes are half of the problem)

Apologies for the lack of knowledge I have vague knowledge of how AutoIt works but have always had issues getting commands passed through correctly. Powershell however.... this is a first attempt but that part is working fine i just cant launch it using AutoIT at the moment.

Thanks

Dan

Link to comment
Share on other sites

Try this:

$start = "C:\Windows\System32\windowspowershell\v1.0\powershell.exe -noexit -STA -Command "
$middle = "C:\Program Files\ApplicationDir\TAME\HRMenu\Start\Start.ps1 "
$end = '-engine Server01.domain.local -session TAME_TEST -stage DEV -useCredential Server01\'

ConsoleWrite(@ComSpec & ' /c ' & $start & $middle & $end)
Run(@ComSpec & ' /k ' & $start & $middle & $end, @SystemDir, @SW_SHOW)

Br,

UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

Hi UEZ,

I got back a powershell error so something is still slightly off:

The string starting:

At line:1 char:144

+ C:Program FilesApplicationDirTAMEHRMenuStartStart.ps1 -engine Server01.

domain.local -session TAME_TEST -stage DEV -useCredential Server01 <<<< "

is missing the terminator: ".

At line:1 char:145

+ C:Program FilesApplicationDirTAMEHRMenuStartStart.ps1 -engine Server01.

domain.local -session TAME_TEST -stage DEV -useCredential Server01" <<<<

+ CategoryInfo : ParserError: (:String) [], ParentContainsErrorRe

cordException

+ FullyQualifiedErrorId : TerminatorExpectedAtEndOfString

At the end of the batch file the -useCredential input is specified in quotes, on the console write it looks like it is too but then appears to fail passing it through after that. I think the problem is here but i cant figure out how to send exactly what it wants.

I noticed on another topic there was a . after the -Command but wasnt sure if that was relevant or not, maybe its something AutoIT requires?

Thanks

Dan

Link to comment
Share on other sites

  • Developers

Try:

Run( @comspec & ' /k C:\windows\system32\WindowsPowerShell\v1.0\PowerShell.exe -noexit -STA -Command "& ''C:\Program Files\ApplicaionDir\TAME\HRMenu\Start\Start.ps1'' -engine Server01.domain.local -session TAME_TEST -stage DEV -useCredential 'Server01\'"'

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

Hi UEZ,

Without the quotes on Server01 i get an error earlier in the script:

The term 'C:Program' is not recognized as the name of a cmdlet, function, scri

pt file, or operable program. Check the spelling of the name, or if a path was

included, verify that the path is correct and try again.

At line:1 char:11

+ C:Program <<<< FilesApplicationDirTAMEHRMenuStartStart.ps1 -engine Ser

ver01.domain.local -session TAME_TEST -stage DEV -useCredential Server01

+ CategoryInfo : ObjectNotFound: (C:Program:String) [], CommandN

otFoundException

+ FullyQualifiedErrorId : CommandNotFoundException

Hi Jos,

Using yours i have pretty much the same issue with the quotes, before i run it i can see using the script editor the syntax isnt correct as its highlighted in black as opposed to red like the rest of the text.

When i run it, it returns:

C:PowerShell Test.au3(48,244) : ERROR: syntax error

Run(@comspec & ' /k C:\Windows\System32\WindowsPowerShellv1.0PowerShell.exe -noexit -STA -Command "& ''C:Program FilesApplicationDirTAMEHRMenuStartStart.ps1'' -engine Server01.domain.local -session TAME_TEST -stage DEV -useCredential 'Server01

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

C:PowerShell Test.au3 - 1 error(s), 0 warning(s)

!>16:55:48 AU3Check ended. Press F4 to jump to next error.rc:2

>Exit code: 2 Time: 0.313

Thanks for your help,

Dan

Link to comment
Share on other sites

  • Developers

I missed the single qouotes around the server at the end:

Run(@comspec & ' /k C:\windows\system32\WindowsPowerShell\v1.0\PowerShell.exe -noexit -STA -Command "& ''C:\Program Files\ApplicationDir\TAME\HRMenu\Start\Start.ps1'' -engine Server01.domain.local -session TAME_TEST -stage DEV -useCredential ''Server01\''"')
Edited by 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

I missed the single qouotes around the server at the end:

Run(@comspec & ' /k C:\windows\system32\WindowsPowerShell\v1.0\PowerShell.exe -noexit -STA -Command "& ''C:\Program Files\ApplicationDir\TAME\HRMenu\Start\Start.ps1'' -engine Server01.domain.local -session TAME_TEST -stage DEV -useCredential ''Server01\''"')

Excellent Jos, that works great and its exactly how i wanted it to run in the first place.

I can now continue with the rest of the GUI and functions and hopefully i wont run into anymore syntax issues!

Thanks to you both for your prompt help.

Dan

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...