Jump to content

Running PS1 Script with Parameters


Vivaed
 Share

Recommended Posts

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

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

Link to comment
Share on other sites

11 minutes ago, BrewManNH said:

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

i beg to differ

 

 

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

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

Link to comment
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.

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

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

Link to comment
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!

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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

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

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

Link to comment
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.

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

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

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

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

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

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