Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8130705
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T08:49:18+00:00 2026-06-06T08:49:18+00:00

Code: $exchangesnapin = Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010; $output = shell_exec(‘powershell ‘.$exchangesnapin.’;get-mailboxdatabase 2>&1′); echo( ‘<pre>’ ); echo(

  • 0

Code:

$exchangesnapin = "Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010";
$output = shell_exec('powershell '.$exchangesnapin.';"get-mailboxdatabase" 2>&1'); 
echo( '<pre>' );
echo( $output );
echo( '</pre>' );

Result:

Name                           Server          Recovery        ReplicationType 
----                           ------          --------        --------------- 
Mailbox Database 0651932265    EGCVMADTEST     False           None        
Mailbox Database 0651932266    EGCVMADTEST     False           None    

I tried with

echo( $output[1] );

The result was only a letter ‘N’. I believe its taking the Name column but one character at a time.

$output[1] is 'N', $output[2] is 'a'.

Is there any way I can get the mailbox list into array?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T08:49:21+00:00Added an answer on June 6, 2026 at 8:49 am

    you are trying to execute an external program (powershell) from PHP and have the output as an array.
    In order to execute an external program in PHP, you could use:

    • exec() function
    • shell_exec() function
    • system() function
    • backtick operator
    • process control extensions

    using process control extensions (PCNTL, popen) gives you more control, but takes more code and time. using the execution functions are simpler.

    In this situation, using exec() could help you to have the output of powershell in an array whose each index is a line from the powershell output.

    <?php
    $output = array(); // this would hold the powershell output lines
    $return_code = 0; // this would hold the return code from powershell, might be used to detect execution errors
    $last_line = exec("powershell {$exchangesnapin} get-mailboxdatabase 2>&1", $output, $return_code);
    echo "<pre>";
    // print_r($output); view the whole array for debugging
    // or iterate over array indexes
    foreach($output as $line) {
        echo $line . PHP_EOL;
    }
    echo "</pre>";
    ?>
    

    Please note that (as the documentation says) if you only want to echo the output of powershell, you could use the passthru() function. using exec() uses memory to store the output of the external program, but using passthru would not use this storage, resulting in less memory usage. But the output could not be used for further processing, and is sent to the PHP standard output right a way.

    In the end, please note that external program execution requires careful data validation to reduce the risk of unwanted system effects. Make sure you use escapeshellarg() on the data that constructs the execution command.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Code in here: jsfiddle Demo I wanna to get the div#content height when it
Code snippet: for (int i = 0; i < vals.Length -1; i++) { series1.Points.Add(Convert.ToDouble(vals[i]));
Code output needed: Visual Output : My sql Database 'test' CREATE TABLE IF NOT
Code 1: ArrayList arr = new ArrayList(); arr.add(3); arr.add(ss); Code 2: ArrayList<Object> arr =
Code: static int counter = 0; int add(int x) { counter++; return ++x; }
Code: #include <iostream> using namespace std; #define ADD(x,y) ((x)+(y)) int main( int argc, char**
(code examples are python) Lets assume we have a list of percentages that add
Code: function _() { echo 'hello word'; } Output: Fatal error: Cannot redeclare _()
code: http://jsfiddle.net/WRppV/4/ I should get something like content=> [141, [203, 206, 204, 205], 142,
Code to create new form instance of a closed form using form name I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.