Vivaed

Running PS1 Script with Parameters

24 posts in this topic

Trying to automate the sideload of a Windows Store app via .ps1 script...

RunWait(@ComSpec & ' /c' & 'C:\"WB Resources"\APP_Prod\Add-AppDevPackage.ps1')

Above doesn't work... I assume this is trying to open in CMD.

 

Normally we right click the .ps1 and open with powershell, then we have to type "A" to start the install, it installs and then type any yet to exit.
However I cant get the powershell to even open.

Kind of puzzled here, any suggestions would be a help.

PS I also tried to convert the .ps1 to exe, but that was a huge failure... lol

Share this post


Link to post
Share on other sites



We need to use powershell command for running powershell script through command prompt.

Eg:-

powershell "C:\Dummy Directory 1\Foo.ps1"

Share this post


Link to post
Share on other sites

Try this:

ShellExecuteWait('"C:\WB Resources\APP_Prod\Add-AppDevPackage.ps1"')

If it still doesn't work, try it without the outer single quotes around the path and file name. You can't use Run or @ComSpec with a PS script, you need to use ShellExecute. You were also missing the space after /c as well but that wouldn't have helped anyways.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites
11 minutes ago, BrewManNH said:

You can't use Run or @ComSpec with a PS script

i beg to differ

 

 


,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Share this post


Link to post
Share on other sites
1 minute ago, iamtheky said:

i beg to differ

 

Beg all you wish, but you are NOT using Run to run the ps1 script, you are using Run to run the powershell program and passing the script name to it. That is a major difference in what the OP was using in his script. Perhaps it would have been clearer to have said "You can't use Run or @ComSpec to directly run a PS script", but my point still stands as accurate.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

no its not, you said you cant use X with Y.  When clearly you can, you just must specify the application.  If accurate = misleading then yes, you did great, head pats all around.


,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Share this post


Link to post
Share on other sites
21 minutes ago, BrewManNH said:

You can't use Run or @ComSpec with a PS script,

Hi Vivaed,

 

You can run powershell script with RunWait command, like we run a powershell script in command prompt.  But ShellExecuteWait can also be used.

 

Thanks

Anoop

Share this post


Link to post
Share on other sites
23 minutes ago, BrewManNH said:

Try this:

ShellExecuteWait('"C:\WB Resources\APP_Prod\Add-AppDevPackage.ps1"')

If it still doesn't work, try it without the outer single quotes around the path and file name. You can't use Run or @ComSpec with a PS script, you need to use ShellExecute. You were also missing the space after /c as well but that wouldn't have helped anyways.

This gets the Shell to open, I see red text with errors but it closes, thanks for the progress!

Share this post


Link to post
Share on other sites
6 minutes ago, Vivaed said:

This gets the Shell to open, I see red text with errors but it closes, thanks for the progress!

What errors you are getting. You may have to set the execution policy.

Share this post


Link to post
Share on other sites
Just now, Anoop said:

What errors you are getting. You may have to set the execution policy.

Not showing, the window closes when it errors, I wish I could pump the output to the console... is that possible?

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

7 minutes ago, Vivaed said:

Not showing, the window closes when it errors, I wish I could pump the output to the console... is that possible?

Can you try with command prompt?

Edited by Anoop

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

14 minutes ago, iamtheky said:

no its not, you said you cant use X with Y.  When clearly you can, you just must specify the application.  If accurate = misleading then yes, you did great, head pats all around.

Are you trying to be pedantic about this, or do you have a point? I said, and I still say, you can't run a ps1 file with Run. You HAVE to use the powershell.exe program to run it. To run it directly without specifying the program you HAVE to use ShellExecute. Where was I wrong in what I wrote before? You can not use Run to directly execute a .ps1 file, so you can't use x with y is 100% accurate if read as it is written and not with a hidden agenda you seem to have.

Edited by BrewManNH

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

#13 ·  Posted (edited)

1 hour ago, Anoop said:

Cam you try with command prompt?

Keeps throwing an error about the space between C;\WB and Resources

C:\Windows\System32\WindowsPowerShell>powershell.exe -Command "C:\WB Resources\APP_Prod\Add-AppDevPackage.ps1"
C:\WB : The term 'C:\WB' is not recognized as the name of a cmdlet, function, script 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:1
+ C:\WB Resources\Wellbeats.Universal_2.2.41.0_Prod\Wellbeats.Universal ...
+ ~~~~~
    + CategoryInfo          : ObjectNotFound: (C:\WB:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

# I am running As Admin

# I also triple checked the path and all spelling, everything looked good

Edited by Vivaed

Share this post


Link to post
Share on other sites

#14 ·  Posted (edited)

sorry, late to the game.  Have you tried wrapping that entire command in single quotes?  If you look at my post you will see i have separated the command, and then you could just call $commmand wrapped in quotes, which also usually works just fine.

something like:

$command = "C:\WB Resources\APP_Prod\Add-AppDevPackage.ps1"

run('powershell.exe -Command ' & '"' & $command & '"')

 

*idk if its chrome or IPB (or a combo) but code boxes are jacked

Edited by iamtheky

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Share this post


Link to post
Share on other sites
9 minutes ago, iamtheky said:

sorry, late to the game.  Have you tried wrapping that entire command in single quotes?  If you look at my post you will see i have separated the command, and then you could just call $commmand wrapped in quotes, which also usually works just fine.

something like:

$command = "C:\WB Resources\APP_Prod\Add-AppDevPackage.ps1"

run('powershell.exe -Command ' & '"' & $command & '"')

 

*idk if its chrome or IPB (or a combo) but code boxes are jacked

Just tried it, didnt see a window or anything, not sure if even ran, but the app is not installed

Share this post


Link to post
Share on other sites
1 hour ago, BrewManNH said:

You can not use Run to directly execute a .ps1 file, so you can't use x with y is 100% accurate if read as it is written and not with a hidden agenda you seem to have.

I'm not arguing semantics, thats why i quoted you.  Your statement is not accurate. Your revisions are better, but revisionist history is for the badged folk.  You seem to think you need to be right and could not possibly have misrepresented the facts.


,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Share this post


Link to post
Share on other sites
1 minute ago, Vivaed said:

Just tried it, didnt see a window or anything, not sure if even ran, but the app is not installed

do a cmd /k powershell.exe so you can watch it and we can see the failure


,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Share this post


Link to post
Share on other sites
5 minutes ago, iamtheky said:

do a cmd /k powershell.exe so you can watch it and we can see the failure

Still barking an error about the space:

C:\WB : The term 'C:\WB' is not recognized as the name of a cmdlet, function,
script 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:1
+ C:\WB Resources\Wellbeats.Universal_2.2.41.0_Prod\Wellbeats.Universal ...
+ ~~~~~
    + CategoryInfo          : ObjectNotFound: (C:\WB:String) [], CommandNotFou
   ndException
    + FullyQualifiedErrorId : CommandNotFoundException

 

My code:

$iDir = "C:\WB Resources\Wellbeats.Universal_2.2.41.0_Prod\Wellbeats.Universal_2.2.41.0_Prod\Add-AppDevPackage.ps1"

Run('cmd /k C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -Command ' & '"' & $iDir & '"')

 

I wish I could change the space but we have 2000 systems in the field with this naming convention

Share this post


Link to post
Share on other sites

The -Command parameter is for directly running command strings with PS, not for running scripts with it. Try it without using the -Command parameter.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

Use -File instead of -Command.  

 

Adam

 

1 person likes this

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

  • Similar Content

    • AnonymousX
      By AnonymousX
      Hello,
      What command would I use to open the following folder directories for:
      Computer/This PC (windows 7/Windows 10)
      Libraries\documents
      Libraries\Pictures
      I know:
       Run("Explorer.exe " & $filepath) ShellExecute($filepath) can be used to open folder locations when you type in the full directory such as "C:\Users\%username%\Documents" but I'm trying to figure out how to use these windows short paths. 
      Thanks,
    • StMaSi
      By StMaSi
      I'm attempting to code a Run or RunWait command that is a little on the long side and contains multiple sets of embedded quotes (as it would be issued from a CMD prompt), but can't for the life of me figure out the containing quotes as pertains to AutoIt. Here's the one-line command as it would be issued via a CMD prompt...
      "\\AppServ\G$\Connectivity\Clients\Citrix\Receiver\14.5.0.10018\CitrixReceiver.exe" ADDLOCAL="ReceiverInside,ICA_Client,WebHelper,SSON,AM,SELFSERVICE,USB,DesktopViewer,Flash,Vd3d" ALLOWADDSTORE=A ALLOWSAVEPWD=A ENABLEPRELAUNCH=Y ENABLE_SSON=Yes STORE0="AppStore;https://receiver.domain.net/Citrix/Apps/discovery;on;AppStore" /EnableCEIP=false /includeSSON /noreboot /silent I've tried so many different combinations of surrounding quotes with Run and RunWait, I just don't understand why it's this difficult to get past this.
      Can anyone assist with this?
      Thank you.
    • WoodGrain
      By WoodGrain
      Hi guys,
      This is probably an obvious one, but I really don't use this command at all so am hoping you can spot my mistake.
      I'm running a powershell script on a schedule with the following script in a function, the function is being called in a loop, but the console process is not closing in the background and I end up with a bunch of console windows running in the background:
      Run(@comspec & ' /k PowerShell.exe -STA -NonInteractive -ExecutionPolicy ByPass -Command "& ''Z:\Powershell\365\GetNextDetails.ps1'' "', "", @SW_HIDE) Thanks!
    • dumbledown
      By dumbledown
      Hi,
      I'm new to AutoIt but it looks great.
      I want to get the text from Internet Explorer when hovering the mouse over an image, the statusbargettext function appears to be the way to go.
      When running via a hotkey I return a blank, but the msgbox works. Do you know what I'm doing wrong?
      Thanks
      HotKeySet("!x", "RecordURL") ;wait for ALT-a keystroke While 1 ;loop forever to wait for the keypress Sleep(100) ;no need to kill the CPU WEnd Func RecordURL() #include <MsgBoxConstants.au3> AutoItSetOption("WinTitleMatchMode", 2) Local $sText = StatusbarGetText("Internet Explorer") MsgBox($MB_SYSTEMMODAL, "", "Internet Explorer's status bar says: " & $sText) EndFunc