Quantcast
Channel: IIS Field Readiness – blog of the European IIS team
Viewing all articles
Browse latest Browse all 131

Using Powershell script from PHP

$
0
0

The information from this blog POST has been compiled with the help of the following engineers:

  • Regis DAMONGEOT – société SMILE
  • Theve THAVASOTHY – société STERIA
  • Gregory CHARLET – société STERIA

There are various blogs & examples on the Internet showing how to use PowerShell in ASP.NET. A typical usage scenario consists to use Exchange PowerShell scripts from a web server application in order to manage mailboxes. An example of this can be found here : HOWTO: Using PowerShell in ASP.NET (.NET Framework 2.0). It's also possible to use PowerShell from PHP but, in this case, you have to be aware of the following caveats:

  1. The Powershell script called from PHP may hang when STDIN is redirected (this is typically the case when PHP is used as a CGI process). This problem is documented in a few places :

    executing a Powershell script from php
    PowerShell.exe can hang if STDIN is redirected

    In order to avoid the hang, you'll need to use the undocumented parameter "-InputFormat none" when your PHP script instantiates Powershell:

    C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -InputFormat none -File file.ps1

     

  2. If the Powershell script you are using from PHP is .Net based (Exchange PowerShell scripts are using managed code), you may face a second hang scenario. If you debug this hang or get a network trace, you'll notice that the hang is caused by the .Net framework trying to fetch a CRL (http://crl.microsoft.com/pki/crl/products/CodeSigPCA.crl). This issue is described in this blog: Make sure you have an Internet connection when using signed assemblies and similar symptoms can be found in this article: Exchange Server 2007 managed code services do not start after you install an update rollup for Exchange Server 2007. One way to resolve this issue consists to create a manifest file for Powershell in order to prevent signed assemblies signature checks :

    %systemroot%\system32\WindowsPowerShell\v1.0\powershell.exe.config

    <runtime>
            <generatePublisherEvidence enabled="false"/>
    </runtime>

Please note that the above information applies if you are calling Powershell script from PHP on either IIS or Apache. We hope this blog will save you some research time!

Emmanuel Boersma

 


Viewing all articles
Browse latest Browse all 131

Trending Articles