유효한 powershell 스크립트를 실행하는 데 문제가 있습니다 (cmd로 테스트). 나는 스크립트가 사용자가 사무실에 존재하는지 테스트 해보고 싶지만 cmd에서는 정상적으로 실행되는 동안 인증은 PHP를 거치지 않을 것이다.PHP exec를 사용하여 powershell 스크립트를 실행할 때의 문제
서버는 Windows 2008 R2, IIS 7.5, PHP 5.4 NTS입니다.
저는 일반적으로 리눅스 사용자입니다.이 MS가 큰 일을하는 데 어려움을 겪고 있으므로 어떤 제안이라도 정말 고맙게 생각합니다.
$username = "[email protected]_domain"
$password = "password"
$secstr = New-Object -TypeName System.Security.SecureString
$password.ToCharArray() | ForEach-Object {$secstr.AppendChar($_)}
$cred = new-object -typename System.Management.Automation.PSCredential -argumentlist $username, $secstr
Import-Module MSOnline -force
Connect-Msolservice -Credential $cred
Get-MsolUser -UserPrincipalName [email protected]_domain
와 PHP 부분 :
exec("powershell -Command C:/inetpub/wwwroot/office365/test.ps1 < NUL", $output);
echo '<pre>';
print_r ($output);
echo '</pre>';
출력 결과 :
Array
(
[0] => Connect-MsolService : Exception of type 'Microsoft.Online.Administration.Automa
[1] => tion.MicrosoftOnlineException' was thrown.
[2] => At C:\inetpub\wwwroot\office365\test.ps1:8 char:20
[3] => + Connect-Msolservice <<<< -Credential $cred
[4] => + CategoryInfo : OperationStopped: (:) [Connect-MsolService], Mic
[5] => rosoftOnlineException
[6] => + FullyQualifiedErrorId : 0x80070002,Microsoft.Online.Administration.Autom
[7] => ation.ConnectMsolService
[8] =>
)