【问题标题】:Problems running powershell script with php exec使用 php exec 运行 powershell 脚本时出现问题
【发布时间】:2013-04-10 11:20:25
【问题描述】:

我无法运行有效的 powershell 脚本(从 cmd 测试)。我希望脚本测试用户是否存在于 Office 365 上,但在 cmd 中正常执行时,身份验证不会通过 php。

服务器是 windows 2008 R2, IIS 7.5, PHP 5.4 NTS。

我是一般的 linux 用户,我很难让这个 MS 的东西长时间工作,所以任何建议都非常感谢。

这是我的 powershell 脚本:

$username = "adminuser@my_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 student@my_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] => 
)

【问题讨论】:

    标签: php windows iis powershell exec


    【解决方案1】:

    我找到了解决办法。

    尝试:

    从源中复制名为MSOnlineMSOnline Extended 的文件夹

    C:\Windows\System32\WindowsPowerShell\v1.0\Modules\

    到文件夹

    C:\Windows\SysWOW64\WindowsPowerShell\v1.0\Modules\

    然后在 PS 中运行 Import-Module MSOnline,它会自动获取模块 :D

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-06-02
      • 1970-01-01
      • 2010-10-11
      • 1970-01-01
      • 2015-09-12
      • 1970-01-01
      • 1970-01-01
      • 2020-08-14
      相关资源
      最近更新 更多