Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用php运行powershell脚本_Php_Powershell - Fatal编程技术网

使用php运行powershell脚本

使用php运行powershell脚本,php,powershell,Php,Powershell,我有一个包含powershell脚本的文件,该脚本必须根据我提交给php表单的值来运行 我已经知道了如何运行行命令。如果我能将表单值作为输入传递给shell脚本并获得输出,那就太好了 关于如何将表单值发布到powershell Read host元素,有什么想法吗 提前感谢: 编辑:如果有人能告诉我一种通过php响应Read Host的方法,那也很好:在这种情况下,我不会使用Read Host,因为它只对需要提示用户手动输入值的交互式脚本非常有用 因为您希望从php调用脚本,所以使用参数会更好。

我有一个包含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最好问一个新问题,因为这是一个不同的主题。你能检查一下这个链接吗?