0

I have a file which contains a powershell script that has to be run depending on values i submit to a php form.

I have already figured out how to run linewise commands.It would be great if I could pass the form values as an input to the shell script and get the output.

Any ideas as to how I could post the form values to the powershell Read-host element?

Thanks in advance :)

Edit: If someone could please let me know a way to respond to Read-Host via php that would also be great :)

2
  • Can you provide some examples of what you have tried so far? Commented Mar 17, 2017 at 9:13
  • I have no clue as to how to input values to Read Host as of yet Commented Mar 17, 2017 at 9:45

1 Answer 1

1

I would not use Read-Host in this case as it's only really useful for an interactive script where the user needs to be prompted to manually input values.

As you want to call the script from php, using parameters would be better. This way you can provide input to your script from the command line.

Updating this example script to use parameters...

$computerName = Read-Host -Prompt "Enter your Computer Name"
$filePath = Read-Host -Prompt "Enter the File Path"

Write-Host "$computerName is your computer name!"
Write-Host "Your files are in $filePath location"

Which would generate the following output when run

PS C:\> Get-Something.ps1

Enter your Computer Name: SERVER1
Enter the File Path: C:\folder
SERVER1 is your computer name!
Your files are in C:\folder location

You would use parameters like this:

Param(
    [string]$computerName,
    [string]$filePath
)

Write-Host "$computerName is your computer name!"
Write-Host "Your files are in $filePath location"

Which would generate the following output when run

PS C:\> Get-Something.ps1 –computerName SERVER1 –filePath C:\folder

SERVER1 is your computer name!
Your files are in C:\folder location
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks loads. Is there also a method I could use to assign specific parts of the output to a php variable?
@Sandushi It would be best to ask a new question as it's a different subject to this one.
could you please check this link stackoverflow.com/questions/42918185/…?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.