1
我有麻煩運行有效的PowerShell腳本(從CMD測試)。我希望腳本測試用戶是否存在於Office 365上,但身份驗證不會通過php傳遞,而是在cmd中執行正常。運行PowerShell腳本與PHP執行問題
服務器是Windows 2008 R2,IIS 7.5,PHP 5.4 NTS。
我在一般的Linux用戶,我有麻煩讓這個MS的事情工作大時間,所以任何建議是非常感激。
這裏是我的PowerShell腳本:
$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] =>
)