2013-04-10 66 views
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] => 
) 

回答

1

我找到了修复。

尝试:

复制称为从源头MSOnlineMSOnline Extended文件夹

C:\ WINDOWS \ SYSTEM32 \ WindowsPowerShell \ V1.0 \模块\

文件夹

C:\ Windows \ SysWOW64 \ WindowsPowerShell \ v1.0 \模块\

然后在PS运行导入模块MSOnline,它会自动获得模块:d