使用php运行powershell脚本
我有一个包含powershell脚本的文件,该脚本必须根据我提交给php表单的值来运行 我已经知道了如何运行行命令。如果我能将表单值作为输入传递给shell脚本并获得输出,那就太好了 关于如何将表单值发布到powershell Read host元素,有什么想法吗 提前感谢: 编辑:如果有人能告诉我一种通过php响应Read Host的方法,那也很好:在这种情况下,我不会使用Read Host,因为它只对需要提示用户手动输入值的交互式脚本非常有用 因为您希望从php调用脚本,所以使用参数会更好。通过这种方式,您可以从命令行向脚本提供输入 正在更新此示例脚本以使用参数使用php运行powershell脚本,php,powershell,Php,Powershell,我有一个包含powershell脚本的文件,该脚本必须根据我提交给php表单的值来运行 我已经知道了如何运行行命令。如果我能将表单值作为输入传递给shell脚本并获得输出,那就太好了 关于如何将表单值发布到powershell Read host元素,有什么想法吗 提前感谢: 编辑:如果有人能告诉我一种通过php响应Read Host的方法,那也很好:在这种情况下,我不会使用Read Host,因为它只对需要提示用户手动输入值的交互式脚本非常有用 因为您希望从php调用脚本,所以使用参数会更好。
$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"
运行时将生成以下输出
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
PS C:\> Get-Something.ps1 –computerName SERVER1 –filePath C:\folder
SERVER1 is your computer name!
Your files are in C:\folder location
您可以使用如下参数:
Param(
[string]$computerName,
[string]$filePath
)
Write-Host "$computerName is your computer name!"
Write-Host "Your files are in $filePath location"
运行时将生成以下输出
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
PS C:\> Get-Something.ps1 –computerName SERVER1 –filePath C:\folder
SERVER1 is your computer name!
Your files are in C:\folder location
你能提供一些到目前为止你已经尝试过的例子吗?我不知道如何输入值来读取主机作为yetThanks加载。还有一种方法可以用来将输出的特定部分分配给php变量吗?@Sandushi最好问一个新问题,因为这是一个不同的主题。你能检查一下这个链接吗?