0

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.

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");

If I check the available modules in PS1 via PHP, I can find the MSOnline but no loaded commands. Please see attached picture.

enter image description here

Chyornaya Vdova
  • 94
  • 2
  • 2
  • 7

1 Answers1

0

2 Possible 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

Chyornaya Vdova
  • 94
  • 2
  • 2
  • 7