2013-12-17 5 views
1

나는 PHP에 익숙하고 WAMP를 사용하여 ... PHP를 사용하여 powershell 스크립트를 호출하지만 제출시 내 출력을 보여주지 않습니다. 여기PHP Powershell 스크립트

코드입니다 :

HTML : 
    <html> 
    <head> 
    <title>Tool</title> 
    <body><center><h1>Welcome</h1><center/> 
    <p><img src="images/google.gif"></p> 
    <form action="welcome.php" method="post"> 
    <input type="text" name="number"><br><br> 
    <input type="submit" value="Submit"> 
</form> 

    welcome.php code : 

    <html> 
    <body> 
    <?php 
    $CMD = 'powershell -command C:\wamp\www\Badge\scripts\badge.ps1 ' . $_POST['number']; 
    ?> 
    </body> 
    </html> 

난 그냥 빈 페이지를 얻을 수 있지만 제출시가/배지/welcome.php을 localhost로 페이지를 리디렉션

내가이

같은 주면 내 파워 쉘 코드가 실행

powershell.exe -command C:\wamp\www\Badge\scripts\badge.ps1 12345 and it displays my name. 

심지어도 PHP이 갖는 시도 :

<?php 
shell_exec ($_POST("powershell.exe -command C:\wamp\www\Badge\scripts\badge.ps1 ['number']"); 
shell_exec("exit"); 
    ?> 
01,

그래서 무엇이 잘못되었거나 내가 무엇을 변경해야하는지에 대한 아이디어는 php를 사용하여 html의 텍스트 값을 powershell로 호출해야합니다.

+0

당신은 당신의 포스트에서 파워 쉘 코드를 추가 할 수 있을까요? –

+0

경우 ((은 Get-PSSnapin |! 경우 - 오브젝트 {. $ _ 이름 -eq "Quest.ActiveRoles.ADManagement"})) { ADD-PSSnapin Quest.ActiveRoles.ADManagement } 은 Get-QADuser -ObjectAttributes @ { 'extensionattribute10'= $ args [0]} | 이름 선택 – user3111077

답변

0

스크립트를 전달하는 중일 때는 명령 플래그가 필요하지 않습니다. 또한 PHP를 통해 스크립트를 실행할 때 기본 ExecutionPolicy 설정에 의해 차단되면 플래그로이를 덮어 쓸 수 있음을 알았습니다. "설정 - ExcetuionPolicy을 RemoteSigned를"당신이 PHP에 PowerShell을 사용하기 전에 윈도우 (NO 사용 PHP)에 PowerShell을 열어야합니다,

$cmd = 'powershell.exe -ExecutionPolicy RemoteSigned C:\wamp\www\Badge\scripts\badge.ps1 '.$_POST['number']; 
if(exec($cmd, $out)){ 
    echo join($out); 
} 
0

1.Firts과 (따옴표없이)를 PowerShell 창에서이 스크립트를 입력 :이 시도 . 이 변경 내용을 확인하려면 Windows PowerShell (따옴표 제외)에서이 명령을 입력하면 "RemoteSigned"텍스트를 표시하면 "Get-ExecutionPolicy"가 성공적으로 변경됩니다.

2. 이제, powershell에 액세스 할 때 PHP를 사용할 수 있습니다. exec comand와 powershell에서는 큰 따옴표를 사용할 수 없습니다. 나는 그 이유를 모르지만 그 반환 오류를 시도 할 때. 작은 따옴표로이 코드를 사용해보십시오.

$output = array(); 
$return_code = 0; 
$last_line = exec('powershell.exe Write-Host Hello World! ', $output, $return_code); 

echo "<pre>"; 
print_r($output); 
echo "</pre>"; 

그리고이 코드는 ps 스크립트를 사용합니다.

$output = array(); 
$return_code = 0; 
$last_line = exec('powershell.exe C:\xampp\htdocs\powershell\powerscript2.ps1 2>&1 ', $output, $return_code); 

echo "<pre>"; 
print_r($output); 
echo "</pre>"; 

그리고이 샘플 powerscript2.ps1

# Filename: Hello.ps1 
Write-Host 
Write-Host 'Hello World!' 
Write-Host "Good-bye World! `n" 
# end of script