Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

Need help with Read-Host

$
0
0

I have a script that installs java. In the script I have a line of code that works properly:

$sb={
Start-Process 'C:\Temp\jre-7u25-windows-x64.exe' -ArgumentList '/s' -verb runas -Wait}

It starts a process named jre-7u25-windows-x64.exe, that I can view in task manager, and java is successfully installed silently.

Now I am working with Read-Host parameters so that the script prompts me for the names and locations of files, so I do not need to modify the script. Everything in my code is working properly except this line. What I would like to have working is this:

$process = Read-Host 'Enter the name of the .exe being installed ie. Java.exe'
$arglist = Read-Host 'Enter the switches to be used ie. /s /qn'
$sb={
Start-Process "C:\Temp\$process" -ArgumentList "$arglist" -verb runas -Wait}  

This way, the $process and $arglist can be variables, which can be modified when the box pops up asking for input. However, it's not working and I'm stumped. Here is ther error I'm getting:

This command cannot be executed due to the error: No application is associated with the specified file for this operation.

I also get the same error if I remove the $arglist and use just:

$sb={
Start-Process "C:\Temp\$process" -ArgumentList '/s' -verb runas -Wait}

So, the error has to be related to the $process = read-host ...... statement, I'm just not sure how to get it to work. Any help or ideas of an alternate means to make this work is greatly apprecieated!


Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>