Running Powershell command from PHP returns blank page

Hi. :-)
I have this script :
<?php
$q = shell_exec('powershell Get-Help');
echo $q;
?>
This works well and gives me output.
But... When I change Get-Help with Get-VM it gives me blank page as ouput. I have simillar problems with other Hyper-V cmdlets.
This is code 1:
<?php
$q = shell_exec('powershell Get-VM');
echo $q;
?>
This code gives me blank page.
Code 2:
<?php
$q = shell_exec('powershell Start-VM 'Vm1'');
echo $q;
?>
This code gives me that it cannot find VM with that name.
What's the problem, what to change in script or system settings.
Note: All this commands WORK and gives me output when I run it from cmd
Things that I did:
 1. Changed execution policy to Unrestricted
 2. Added 2<&1 at the end of shell_exec.
Thanks in advance.

Hi,
I think we should run powershell as adminitrator to get VMs.
Start-Process "$psHome\powershell.exe" -Verb Runas -ArgumentList '-command "Get-VM"'
Regards,
Yan Li
Regards, Yan Li

Similar Messages

  • Printing to PDF from CrystalReportViewing returns blank page

    Hi All,
       I have a web report that I run. When the report generates in the CrystalReportViewer I see my results. However, if I click the button to Print to PDF, it results in a PDF with no data. If I click on the Next button as well to go to the next page in my report, it returns blank results.
    This apparently started happening when I used date parameters being passed to my stored procedure:
            parameterField = report.ParameterFields("@callstdate")
            parameterField2 = report.ParameterFields("@callendate")
    I'm using VS 2008 and CR2008.
    Any ideas why this is happening?
    Thank you in advance,

    1)Any export type I use returns no data on the exported report
    2)Changed PDF to ActiveX and it printed the report with no data
    3)Remove parameters from my webapp and let the Viewer prompt for them. Now PDF works and everything else.
    Here's my code:
        Protected Sub display_report()
            parameterField.CurrentValues.Clear()
            parameterField2.CurrentValues.Clear()
            parameterField3.CurrentValues.Clear()
            CrystalReportViewer2.ParameterFieldInfo.Clear()
            parameterField = report.ParameterFields("@callstdate")
            parameterField2 = report.ParameterFields("@callendate")
            parameterField3 = report.ParameterFields("Group")
            For Each li As ListItem In Me.ListBox1.Items
                If li.Selected = True Then
                    ' Add all parameters value here
                    parameterField3.CurrentValues.AddValue(li.Value)
                End If
            Next
            report.SetParameterValue("@callstdate", CDate(st_date.Text))
            report.SetParameterValue("@callendate", CDate(st_date.Text))
            CrystalReportViewer2.ReportSource = report
        End Sub

  • Sending novell command from PHP

    Hi,
    I am trying to unzip a file from php.
    I am trying to run a unzip command from phpm but the novell server won't take it.
    when i do: <?php exec("unzip DATA1:/zipfile.zip"); ?>
    i get: unable to find load file SYS:/TMP/UNZIP
    when i do: <?php exec("echo unzip DATA1:/zipfile.zip"); ?>
    i get: unable to find load file SYS:/TMP/ECHO
    when i do: <?php exec("echo unzip "); ?>
    i get: unzip.nlm load status KenelOnly
    Does someone know how to send a command from php to Novell correctly??
    Thank you,

    Have you tried specifying the path with something like
    <?php exec("sys:/system/unzip DATA1:/zipfile.zip"); ?>
    Wolfgang
    "Flex Travel - Higo Rocha Cidario" <[email protected]> wrote in message
    news:oE0uh.7409$[email protected]..
    > Hi,
    >
    > I am trying to unzip a file from php.
    > I am trying to run a unzip command from phpm but the novell server won't
    > take it.
    >
    > when i do: <?php exec("unzip DATA1:/zipfile.zip"); ?>
    > i get: unable to find load file SYS:/TMP/UNZIP
    >
    > when i do: <?php exec("echo unzip DATA1:/zipfile.zip"); ?>
    > i get: unable to find load file SYS:/TMP/ECHO
    >
    > when i do: <?php exec("echo unzip "); ?>
    > i get: unzip.nlm load status KenelOnly
    >
    > Does someone know how to send a command from php to Novell correctly??
    >
    > Thank you,
    >

  • Running Unix Command from WEB-APPLICATION

    Hi all,
    I want to run unix command from a java-based web application. the basic code part is this ---
    public class RunCommand
          public String runIt()
              String s = null, returnString = "";
              Process p=null;
              try
                       Runtime rt = Runtime.getRuntime();
                  p = rt.exec("sh testPOC.ksh");
                  p.waitFor();
                  BufferedReader stdInput = new BufferedReader(new
                       InputStreamReader(p.getInputStream()));
                  BufferedReader stdError = new BufferedReader(new
                       InputStreamReader(p.getErrorStream()));
                  // read the output from the command
                  returnString += "Here is the standard output of the command:<br>";
                  while ((s = stdInput.readLine()) != null) {
                      returnString += s;
                  // read any errors from the attempted command
                  returnString += "Here is the standard error of the command (if any): <br>";
                  while ((s = stdError.readLine()) != null) {
                      returnString += s;
              catch (IOException e)
                  returnString += "exception happened - here's what I know: ";
                  returnString += "error-> " + e.getMessage();
              catch(Exception e)
                returnString += "exception happened - here's what I know: ";
                  returnString += "error-> " + e.getMessage();
              return returnString;
      }this class is kept as an inner class. The control comes to its outer class, from servlet, from which the runit() is called. but the exception is occuring at line of p=rt.exec(.....). it tells "<command name> : not found transaction completed" [got this using getMessage() method].
    i am unable to show(and see, too) the stacktrace, because i don't have access to that test environment and its log. i can't run this in local because its windows one.
    now can anyone tell me, where is the problem. is there any limitation in web application server/container? this was successful when i used command prompt writing a .java file. Please help me. Thanks in advance...

    Friends, i've got, where the problem is.
    when we run a class file directly from a command prompt, we get an environment with that shell window. but for a servlet application running these kind of commands from a class creates kind of child processes. each and every command is executed as a child process of jvm and don't get those environment. we have 'PATH' variable in the environment. when a command (say, 'dir' or 'sh' or 'ls', etc.) is executed, the shell first search for that executable file (i.e. dir / sh / ls) in the given paths in the variable 'PATH'. this is not available for the child commands of jvm. hence the basic commands are searched in the current directory of the jvm and they are failed.
    i solved the problem giving full path of the commands. like :
    p = rt.exec("/bin/sh runningScript.ksh")

  • Updating UCCX Application returns blank page

    Hi,
    We have IPCC Express 4.5, when adding new application or updating existing apps, it returns blank page. Before, it will work again when we restart the server but now, it just won't work. Is there a known bug for this one? CAn anyone of you help me? We have upcoming scripts to develop and we cannot do any thing to apply it. Thanks in advance.
    Len

    Hi
    I would check the c:\program files\wfavvid\log\MADM logs for any major EXCEPTIONS (search for them in Caps, and try to make sense of what they are telling you
    If you don't have any luck with that, it's possible to delete the appadmin website from Tomcat and it will rebuild the site when you next restart the Node Manager. Go into c:\program files\wfavvid\tomcat_appadmin\webapps, and delete the appadmin folder. There will also be an appadmin.war file there, don't delete that as it contains the compressed website files. When you restart the node, it will be rebuilt and may be fixed.
    Regards
    Aaron
    Please rate helpful posts....

  • Run powershell command in app part on submitting item in O365 Sharepoint list.

    I need to fire an powershell command through app part as soon as i have submitted details or form on the list.
    As powershell command requires inputs, i have created list and a form into it, i mapped the column with the powershell input, but the commands is not running or firing, please help.
    Regards
    Mohit Jain

    Hi,
    According to your description, my understanding is that you want to run a Powershell command when submitting a form on the list to create mailbox for user.
    As your environment is Office 365, I suggest you can create a web service to call the PowerShell Command using C#. Then in the office 365 list, you can create a remote event receiver to trigger the web service to
    achieve it.
    Here are some detailed articles for your reference:
    http://msdn.microsoft.com/en-us/library/ms464040%28v=office.12%29.aspx
    http://www.codeproject.com/Articles/18229/How-to-run-PowerShell-scripts-from-C
    http://msdn.microsoft.com/en-us/library/office/jj220043(v=office.15).aspx
    Best Regards
    Forum Support
    Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Subscriber Support, contact
    [email protected]
    Zhengyu Guo
    TechNet Community Support

  • Running ssh command from java and then answering password prompt

    Hi,
    I have a situation that has not solved yet. I am running ssh command from unix terminal without any problem, and then i enter password.
    For example :
    [oracle@fuata]:/export/home/oracle> ssh -N [email protected] -L 9901:127.0.0.1:9999
    Password:
    It is working. I have question that how can i perform this in java? I am thinking that i can run ssh command by using Runtime Class, it is ok. But how can i answer the password? I am a bit confused. Is there any example looks like this?
    Thanks for responses.

    futi wrote:
    Thanx. Firstly i insisted to do this without jsch but actually this is harder than jsch. I edit some of code pieces PortForwardingL.java and could run it. It works problem-free. Could you say why you "insisted" on this approach. It can't be for speed+ since jsch is very fast. It can't be for portability+ since jsch is portable but the use of Runtime.exec() requires the installation of ssh software. It can't be because of limitations+ since jsch is a fully featured library. It can't be for security+ since jsch is secure. It can't be for ease of use+ since jsch is much easier to use than ssh with Runtime.exec(). Unless it's a licensing issue, it can't be for commercial+ reasons since jsch is free. The only reason I can think of why one would "insisted" on this approach is if it is for some college project.

  • Running ls command from Java stroed procedure no output

    Hi ,
    I am trying to run ls command from java stored procedure in oracle
    Process p = Runtime.getRuntime().exec("ls");
    BufferedReader stdInput = new BufferedReader(new
    InputStreamReader(p.getInputStream()));
    BufferedReader stdError = new BufferedReader(new
    InputStreamReader(p.getErrorStream()));
    // read the output from the command
    System.out.println("output of the command run:\n");
    while ((s = stdInput.readLine()) != null) {
    System.out.println(s);
    from java stored procedure in oracle.
    i get output of println statments but it does not go into while loop to print from stdInput.
    Result of running Java stored procedure is -
    output of the command run:
    Call completed.
    when i run the program on client side it works fine.
    Has anybody tried this from java stroed procedure.
    Thanks,
    Jag

    Jag,
    Actually, the question of whether it works for me seems to depend on the version of the OS (or Oracle). On RedHat Linux (Oracle 8.1.6) it didn't work at all, but on Solaris (Oracle 9.0.2) it did. Here's the output from that run:
    SQL> /
    output of the command run:
    init.ora
    initDBPart9i.DBPSun01.ora
    initdw.ora
    lkDBPART9I
    orapw
    orapwDBPart9i
    spfileDBPart9i.ora
    Done
    PL/SQL procedure successfully completed.
    But, I did need to change a line of your code to this:
    Process p = Runtime.getRuntime().exec("/usr/bin/ls");
    your original was:
    Process p = Runtime.getRuntime().exec("ls");
    You might consider, if possible, use of some of the Java File classes instead of ls, as this might make things more predictable for you. There were some examples in oramag.com a few months ago, but they were pretty simple (you might not need them).
    Hope this helps,
    -Dan
    http://www.compuware.com/products/devpartner/db/oracle_debug.htm
    Debug PL/SQL and Java in the Oracle Database

  • Run OS command from Oracle

    Hi All!!
    Which package can help me to run OS command from SQL script?
    Thanks.

    If you are using SQL*Plus to execute the script, you can use the SQL*Plus command HOST. If you are trying to execute an operating system command from a PL/SQL block (i.e. a stored procedure), you would need to use an external procedure or a Java stored procedure that uses Java's shell functionality.
    Justin
    Distributed Database Consulting, Inc.
    http://www.ddbcinc.com/askDDBC

  • Is it possible to run host command from SAP environment? How do you run?

    Hi
    Is it possible to run host command from SAP environment? How do you run?
    Thank You

    Hello Subhash
    You will more details in the following thread:
    Re: How to define command for SXPG_COMMAND_EXECUTE
    Regards
      Uwe

  • Google image search in ipad - returns blank page, what's wrong?

    while searching, under image tab, returns blank page.
    what's wrong?

    Works fine for me. Probably a google problem.

  • Administrator Unable To Run Powershell Commands When UPD Enabled

    Hi All,
    We have a single Windows 2012 R2 RDS configured with UPD enabled for the defined collection. So far everything is working fine for standard users; however, the domain administrator can no longer run PowerShell commands (see attached screenshot). 
    I believe this is the result of the UPD "impersonating" the local c:\. How can I get around this for domain administrator accounts?
    Thanks in advance.

    Hi,
    By UPD, you mean user profile disk, right?
    In addition, all non-administrator users can run the exact same PowerShell cmdlet, right?
    What about other PowerShell cmdlets, are administrators able to run them?
    Best Regards,
    Amy
    Please remember to mark the replies as answers if they help and un-mark them if they provide no help. If you have feedback for TechNet Subscriber Support, contact [email protected]

  • Running sqlldr command from PL/SQL Block

    DECLARE
    BEGIN
    END;

    In SQL * plus we can run DOS commands using the following command
    HOST DIR
    HOST DIR/P
    But When we can't run the HOST command in PL/SQL Block..
    I have to Run sqlldr command from PL/SQL Block..
    i tried as follows
    DECLARE
    BEGIN
    EXECUTE IMMEDIATE ' host sqlldr control= bad= ';
    END;
    By
    BalaNagaRaju

  • How to run OS commands from PL/SQL???

    Hi
    Is there any way to run OS commands(Windows Platform) from within PL/SQL?
    Thanks

    APC,
    I am working on Discoverer, having lots of BAs & Workbooks created & stored in Database. Now if i want to move all the workbooks from one place to another (like from development to test or production) i can use Command line interface of Disco to do this. But i don't see any option there to export all the workbooks, so i thought of writing a pl/sql to get all the workbook names from the EUL then fire export Command for each record(although not a good practice but its a one time work). This is the place where i need to run OS command from within PL/SQL. Although it doesn't seem possible now(as you all said) without external procedure.
    Lastly, you are right that "Oracle make databases not operating systems" but my first impression/comment about oracle is:
    "Oracle is far Bigger, Powerful, Complex, Vast and Interesting System than any other..." so i believe it can do/capable doing anything :-)
    thx Ashutosh,
    Host is definitely an option but i can't run it from pl/sql(that i am looking for)..

  • Run PowerShell script from C# writing to input pipe

    Hello,
    I am trying to run a PowerShell script from C# (I have no control over what's in the script). The script may have a prompt like "Press enter to continue". So my goal is:
    1. Get text output from the script (easy, many examples available)
    3. If output contains "Press enter to continue", write a blank line to the running script's pipe to make it finish its job and quit
    4. If output does contain that prompt, just let it exit by itself without sending any input
    Note that commands in this PS script also try to get at script's file path, so I can't read script from file and pass it as text. It has to be executed as a script so it knows where it's located.
    I have done this with .exes and batch files before. All you do in that case is process.StandardInput.WriteLine() which "types" enter into the input stream of script you are trying to control. But this does not work with Power Shell. How do I do this?
    I have tried using PS object model like so:
    using (Pipeline pipeline = runspace.CreatePipeline())
    Command command = new Command(scriptPS, true, true);
       pipeline.Commands.Add(command);
       pipeline.Commands[0].MergeMyResults(PipelineResultTypes.Error, PipelineResultTypes.Output);
       pipeline.Input.Write("\n");
       Collection<PSObject> psresults = pipeline.Invoke();   //...
    But I get an error because the script prompts:
    "A command that prompts the user failed because the host program or the command type does not support user interaction. Try a host program that supports user interaction, such as the Windows PowerShell Console or Windows PowerShell ISE, and remove prompt-related
    commands from command types that do not support user interaction, such as Windows PowerShell workflows."
    I also tried using Process, and running PowerShell with -File switch to execute the script, then write to StandardInput with C#. I get no errors then, but the input is ignored and doesn't make it to PowerShell.
    Please help!

    No man, what kind of answer is that? You should have left it unanswered rather than waste people's time like this. I already seen those links before I posted my question. They address the issue of specifying script parameters, but not
    writing to the input pipe.
    Fortunately I did figure this out by writing a custom script host for PowerShell. Anyone interested can read about this in detail on MSDN (fortunately simple material with samples you can copy paste as I did, so this solution takes little time to implement).
    Implement PSHost interface. Nothing special here, just paste directly from MSDN sample and modify their SetShouldExit function definition to contain just a "return;". Here's the relevant link:
    http://msdn.microsoft.com/en-us/library/windows/desktop/ee706559(v=vs.85).aspx
    Implement PSHostUserInterface interface. This is the ticket to solving this problem
    (see below). Here's the MSDN link:
    http://msdn.microsoft.com/en-us/library/windows/desktop/ee706584(v=vs.85).aspx
    Implement PSHostRawUserInterface. This may not be required (not sure) but I did anyway. Nearly a direct paste from MSDN:
    http://msdn.microsoft.com/en-us/library/windows/desktop/ee706601(v=vs.85).aspx
    So, there are two PSHostUserInterface function implementations that are of particular interest. First is Prompt (read header comment to see why):
    /// <summary>
    /// When script attempts to get user input, we override it and give it input programmatically,
    /// by looking up within promptInput's dictionary<string,string> or lineInput array.
    /// PromptInput dictionary is mapped by input prompt (for example, return "" in response to "Press ENTER to continue")
    /// LineInput is a regular array, and each time the script wants to prompt for input we return the next line in that array;
    /// this works much like piping inputs from a regular text file in DOS command line.
    /// </summary>
    /// <param name="caption">The caption or title of the prompt.</param>
    /// <param name="message">The text of the prompt.</param>
    /// <param name="descriptions">A collection of FieldDescription objects that
    /// describe each field of the prompt.</param>
    /// <returns>Throws a NotImplementedException exception.</returns>
    public override Dictionary<string, PSObject> Prompt(string caption, string message, System.Collections.ObjectModel.Collection<FieldDescription> descriptions)
    Dictionary<string, PSObject> ret = new Dictionary<string, PSObject>();
    foreach (FieldDescription desc in descriptions)
    if (this.promptInput.Count != 0)
    ret[desc.Name] = new PSObject(this.promptInput[desc.Name] + "\r\n");
    else if (this.lineInput != null && this.currentLineInput >= 0 && this.currentLineInput < this.lineInput.Length)
    ret[desc.Name] = new PSObject(this.lineInput[this.currentLineInput++] + "\r\n");
    else
    if (desc.DefaultValue == null)
    ret[desc.Name] = new PSObject("\r\n");
    else
    ret[desc.Name] = new PSObject(desc.DefaultValue);
    return ret;
    Next is PromptForChoice. Here I opted to always return the default choice, but you could rewrite it to read from somewhere to "simulate" reading from input pipe just like the function above:
    public override int PromptForChoice(string caption, string message, System.Collections.ObjectModel.Collection<ChoiceDescription> choices, int defaultChoice)
            return defaultChoice;
    Last but not least, here's a ReadLine implementation (again read header comment):
    /// <summary>
    /// If the LineInput is set, "read" the next line from line input string array, incrementing line pointer/// </summary>
    /// <returns>The characters that are entered by the user.</returns>
    public override string ReadLine()
    if (this.lineInput != null && this.currentLineInput >= 0 && this.currentLineInput < this.lineInput.Length)
    return this.lineInput[this.currentLineInput++];
    else
    return Console.ReadLine();
    Both are exposed as properties:
    /// <summary>
    /// Gets or sets the input pipe override
    /// </summary>
    public string Input
    get
    return string.Join("\n", this.lineInput);
    set
    if (value != null)
    this.lineInput = value.Split('\n');
    this.currentLineInput = 0;
    else
    this.lineInput = null;
    /// <summary>
    /// Gets or sets input pipe override for named prompts
    /// </summary>
    public Dictionary<string, string> PromptInput
    get
    return this.promptInput;
    set
    this.promptInput = value;
    And finally, here's how the whole shebang is used:
    /// <summary>
    /// Runs a powershell script, with input pipe arguments
    /// </summary>
    /// <param name="script">Path of the script to execute, or script text</param>
    /// <param name="inline">Whether or not to execute script text directly, or execute script from path</param>
    /// <param name="unrestricted">Whether or not to set unrestricted execution policy</param>
    /// <param name="parameters">Parameters to pass to the script command line</param>
    /// <param name="inputOverride">Input to pass into the script's input pipe</param>
    /// <param name="inputOverrideName">Input to pass into the script's input pipe, to each prompt by label</param>
    /// <returns>Output lines</returns>
    public static string PowerShell(string script, bool inline, bool unrestricted = false, Dictionary<string, string> parameters = null, string inputOverride = null, Dictionary<string, string> inputOverrideByName = null)
    string output = null;
    ScriptHost host = new ScriptHost();
    (host.UI as ScriptHostUserInterface).Input = inputOverride;
    (host.UI as ScriptHostUserInterface).PromptInput = inputOverrideByName;
    using (Runspace runspace = RunspaceFactory.CreateRunspace(host))
    runspace.Open();
    if (unrestricted)
    RunspaceInvoke runSpaceInvoker = new RunspaceInvoke(runspace);
    runSpaceInvoker.Invoke("Set-ExecutionPolicy Unrestricted");
    using (Pipeline pipeline = runspace.CreatePipeline())
    if (inline)
    pipeline.Commands.AddScript(script);
    else
    Command command = new Command(script, true, true);
    foreach (KeyValuePair<string, string> param in parameters)
    command.Parameters.Add(param.Key, param.Value);
    pipeline.Commands.Add(command);
    pipeline.Commands.Add("Out-String");
    pipeline.Commands[0].MergeMyResults(PipelineResultTypes.Error, PipelineResultTypes.Output);
    Collection<PSObject> psresults = pipeline.Invoke();
    var sb = new StringBuilder();
    foreach (PSObject obj in psresults)
    sb.AppendLine(obj.ToString());
    output = sb.ToString();
    pipeline.Dispose();
    runspace.Close();
    return (host.UI as ScriptHostUserInterface).Output + "\r\n" + output;
    As you can see, I also did some magic with the .Output property. That just accumulates lines of text output by the script in every WriteXXX function implemented in your custom PSHostUserInterface. The end result of all this, is that if you have a script
    that has prompts, choices or reads from standard input, you can execute the script within the context of your custom script host written as above, to control precisely what strings are passed to it in response to prompts.
     

Maybe you are looking for

  • How do I remove whole CDs at a time off my iphone 5?

    I know about swiping but I hate having to delete songs one at a time! Is there a way to delete whole CDs at a time or even everything in music?

  • Do you need adobe photoshop or elements for the ipod with video?

    I am so very frustrated. It took me three days to get quicktime and itunes installed. Finally figured that out. I go to hook up my ipod and it is not working. Ipod has not shown up at all. Instead I get the Windows Hardware finder trying to find the

  • Reading excel  sheet from out side of the server though sql developer.

    Hi ALL, Is it possible to read the excel sheet from the out side of the oracle server. If it possible please send me the sample code.

  • JTable highlights in 1.3.1

    Is there a possibility to highlight the vertical and the horizontal highlights together in JTable with version 1.3.1. I tried table.getColumnsSelectionAllowed() and table.getRowSelectionAllowed() together, and it doesn't work anymore the way it worke

  • First Blackberry--- 4 questions to start!

    I liked the storm a lot but I wasn't keen on the typing.  Typing on the curve is tight, though, because the keys are so small and close.  It was a close call.  I've been playing with my pda all day.....loving it so far and assume I made the right cho