Jump to content
Sign in to follow this  
goss34

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

Share this post


Link to post
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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
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

Share this post


Link to post
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\''"')
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.
  :)

Share this post


Link to post
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

Share this post


Link to post
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
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By antonioj84
      any assistance how to incorporate this powershell command within autoit
       
      powershell.exe -nologo -executionpolicy bypass -WindowStyle hidden -noprofile -command "&Set-WinUserLanguageList -LanguageList fr-CA, en-CA -Force"
    • By Exit
      For my next project I would like to send files with "alternate data streams" by email in ZIP format.
      I can not use any external program like 7-Zip or WinRAR. (They would fit😥)
      Who knows how to create a ZIP file with "alternate data streams" included with the Powershell command "Compress-Archive"? 
      Here a test script:  (save as "ADSTester.cmd")
      @rem Try to create a zip file with alternate data streams (ADS) included @rem Housekeeping @cls @del ADSTester.zip >nul: @RD /S /Q Extracted >nul: @del ADSTester.txt >nul: @rem End of Housekeeping echo This is the ADSTester.txt file >ADSTester.txt echo This is the ADSTester.txt:Part1 file >ADSTester.txt:Part1 echo This is the ADSTester.txt:Part2 file >ADSTester.txt:Part2 dir /r ADSTester.txt @rem See the 3 files @rem **************************************************************** @rem **************************************************************** @rem Please alter the next lines to include the alternate data streams. powershell Compress-Archive -Path .\ADSTester.txt -Update -DestinationPath ADSTester.zip powershell Expand-Archive -Path ADSTester.zip -DestinationPath .\Extracted\ dir /r Extracted\ADSTester.txt @rem Only one file left :-( pause  
    • By ur
      Which Powershell command in the PowerCLI module for VMware ESX used to interact with UI apps?
       
      When I launch any exe/any exeutable using powercli on guest VM using powercli command.
      Invoke-VMScript, I am able to run them in the background but not in the foreground.
       
      i.e., UI apps are not launching but showing the background as running in the task manager.
       
      We need our UI Automation scripts to execute in the VM, but it is not working.
       
      We are able to do in virtualbox and hyper-v but not in vmware esx using powercli.
       
      Please suggest.
    • By ambad4u
      Hello and Good Day to All!
      I am trying to install .NET 3.5 on Windows 10 x64bit via autoit (via ShellExecuteWait + PowerShell).
      If I run this line, it will runs without issues:
      ShellExecuteWait('PowerShell.exe', '-executionpolicy Bypass -File "' & @ScriptDir & '\OJP83BU523.ps1' & '"') "OJP83BU523.ps1" contains: DISM /Online /Enable-Feature /FeatureName:NetFX3 /All /Source:D:\Sources\sxs /LimitAccess
      However, since I won't know in advance the drive letter of the "sources" folder, I created a script to generate a PowerShell Script to give a correct path for it.
      With the modified script below, PowerShell only blinks and nothing happens
      ShellExecuteWait('PowerShell.exe', '-executionpolicy Bypass -File "' & @ScriptDir & '\' & $filename & '"') or
      ShellExecuteWait('PowerShell.exe', '-executionpolicy Bypass -File "' & $filename & '"')  
      I wish I know the difference with "$filename" and "\OJP83BU523.ps1" usage, as for me, it should be the same.
      Attached is my entire autoit script.
      any help is appreciated!, many thanks in advance!
      test.au3
    • By JLogan3o13
      There are a number of posts on the forum regarding use of Selenium in AutoIt. I recently had a go at using the PowerShell Selenium module, and was amazed at how easy it is. Thought I would post an example here; if anyone is interested this could probably be incorporated into AutoIt code pretty easily. 
      Pre-Req - The true star of this script is the ChroPath extension, available for Edge, Chrome and FireFox. With it installed, you just click on the element, select Inspect, and then ChroPath generates the XPath to the element for you. Here is an example based on a simple form I created on one of my sites.
      $myForm = Start-SeChrome -StartURL "http://logancomputerser.com/Appointment.html" -Maximized $firstName = Find-SeElement -Driver $myForm -Timeout 30 -XPath "//input[@id='formElement_First']" $lastName = Find-SeElement -Driver $myForm -Timeout 30 -XPath "//input[@id='formElement_Last']" $address = Find-SeElement -Driver $myForm -Timeout 30 -XPath "//input[@id='formElement_Street1']" $city = Find-SeElement -Driver $myForm -Timeout 30 -XPath "//input[@id='formElement_City']" $zip = Find-SeElement -Driver $myForm -Timeout 30 -XPath "//input[@id='formElement_Zip']" $state = Find-SeElement -Driver $myForm -Timeout 30 -XPath "//select[@id='formElement_State']" $phoneDay = Find-SeElement -Driver $myForm -Timeout 30 -XPath "//input[@id='formElement_DaytimePhone']" $phoneNight = Find-SeElement -Driver $myForm -Timeout 30 -XPath "//input[@id='formElement_EveningPhone']" $email = Find-SeElement -Driver $myForm -Timeout 30 -XPath "//input[@id='formElement_liamE']" $user = Find-SeElement -Driver $myForm -Timeout 30 -XPath "//input[@id='formElement_48564']" $pw = Find-SeElement -Driver $myForm -Timeout 30 -XPath "//input[@id='formElement_f403c']" $submit = Find-SeElement -Driver $myForm -Timeout 30 -XPath "//input[@id='wstForm_Contact_Submit']" $reset = Find-SeElement -Driver $myForm -Timeout 30 -XPath "//input[@id='wstForm_Contact_Reset']" Send-SeKeys -Element $firstName -Keys "Joe" Send-SeKeys -Element $lastName -Keys "Blow" Send-SeKeys -Element $address -Keys "111 S. Main St." Send-SeKeys -Element $city -Keys "AnyCity" Send-SeKeys -Element $zip -Keys "90210" Send-SeKeys -Element $state -Keys "CA" Send-SeKeys -Element $phoneDay -Keys "555.867.5309" Send-SeKeys -Element $phoneNight -Keys "555.888.1212" Send-SeKeys -Element $email -Keys "1Adam12@gmail.com" Send-SeKeys -Element $user -Keys "JBlow" Send-SeKeys -Element $pw -Keys "MyPassword" Start-Sleep 1 Invoke-SeClick -Element $submit Stop-SeDriver -Driver $myForm  
      As mentioned, this is just another way to skin the cat, but I found it a pretty fast way to initiate some easy testing in Selenium, and have used it a couple of times in projects now, both straight through PowerShell and wrapped in AutoIt.
×
×
  • Create New...