none
Loaded PS Modules not included when Powershell is called via PHP RRS feed

  • Question

  • Good day everyone. My question is about calling a powershell script using PHP. So, if I am calling a PS1 script using ActiveDirectory module, there are no issues.

    However, if I am calling PS1 scripts that includes the MSOnline module, it does not work (but PS1 script works locally on the server and MSOnline module is loaded). And as per checking, if the PS1 script is called by PHP, if I issue the get-module command, there is no MSOnline loaded.

    If I run the command locally on server via C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe, it works fine though.

    This is how I call PS1 scripts from PHP:
    shell_exec('C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -executionPolicy Unrestricted -InputFormat none -File PATH\TO\FILE.ps1 '. "$variable");

    Please help in finding a solution for this. Thanks.

    Wednesday, January 17, 2018 5:18 PM

Answers

  • Update: We have discovered 2 different solutions:

    1. Use older version of Powershell Module for Azure AD (but no longer available for download). This works for those who are currently using the version.

    2. User the directory "SysNative" instead of System32 or SysWOW64 when calling the powershell script. This solution was suggested by a Microsoft Engineer:
    C:\Windows\SysNative\WindowsPowerShell\v1.0\powershell.exe -executionPolicy Unrestricted -InputFormat none -File PATH\TO\FILE.ps1


    \_(ツ)_/

    Monday, January 22, 2018 3:32 PM

All replies

  • MsOnline module is only designed to work in a full user session.

    \_(ツ)_/

    Wednesday, January 17, 2018 5:29 PM
  • Update: We have discovered 2 different solutions:

    1. Use older version of Powershell Module for Azure AD (but no longer available for download). This works for those who are currently using the version.

    2. User the directory "SysNative" instead of System32 or SysWOW64 when calling the powershell script. This solution was suggested by a Microsoft Engineer:
    C:\Windows\SysNative\WindowsPowerShell\v1.0\powershell.exe -executionPolicy Unrestricted -InputFormat none -File PATH\TO\FILE.ps1


    \_(ツ)_/

    Monday, January 22, 2018 3:32 PM