Skip to Content

Hello community,

I describe here how to use Microsoft PowerShell 3 inside ABAP. Here and here I describe exemplary how to use COM libraries in the context of UI5. Here now a mixture to show how to use PowerShell inside UI5. This example use a button to start the PowerShell script and a textarea to view the result – function main. In our case all running services. The PowerShell script is stored as plain text object and is executed with the function RunPS. Here the code:

<!doctype html>

<html>

  <head>

    <meta http-equiv=”Content-Type” content=”text/html;charset=ISO-8859-1″ />

    <meta http-equiv=”X-UA-Compatible” content=”IE=edge” />

    <script src=”resources/sap-ui-core.js”

      id=”sap-ui-bootstrap”

      data-sap-ui-libs=”sap.ui.commons”

      data-sap-ui-theme=”sap_bluecrystal”>

    </script>

    <script id=”PS” type=”text/plain”>

#-Begin—————————————————————–

  Get-WmiObject -class Win32_Service | Format-Table -property Name, State

#-End——————————————————————-

    </script>

    <script type=”text/javascript”>

      //-Constants——————————————————

        const OUTPUT_CONSOLE = 0;

        const OUTPUT_WINDOW = 1;

        const OUTPUT_BUFFER = 2;

      //-Variables——————————————————

        var oTextArea;

      //-Sub Main——————————————————-

        function main() {

        

          //-Variables————————————————–

            var oLayout, oButton;

          oLayout = new sap.ui.commons.layout.MatrixLayout();

          oLayout.setColumns(1);

          oLayout.setWidth(“640px”);

          oButton = new sap.ui.commons.Button();

          oButton.setText(“Press me”);

          oButton.attachPress(handleButtonClicked);

          oLayout.createRow(oButton);

          oTextArea = new sap.ui.commons.TextArea();

          oTextArea.setCols(80);

          oTextArea.setRows(25);

          oLayout.createRow(oTextArea);

          oLayout.placeAt(“content”);

        }

      //-Sub HandleButtonClicked—————————————-

        function handleButtonClicked() {

           RunPS();

        }

      //-Sub RunPowerShell———————————————-

        function RunPS() {

          //-Variables————————————————–

            var oPS;

          if (“ActiveXObject” in window) {

            try {

              oPS = new ActiveXObject(“SAPIEN.ActiveXPoSHV3”);

              if (typeof(oPS) == ‘object’) {

                if (oPS.Init(0) != 0) {

                  return;

                }

                if (oPS.IsPowerShellInstalled == 0) {

                  return;

                }

                oPS.OutputMode = OUTPUT_BUFFER;

                oPS.Execute(document.getElementById(‘PS’).text);

                oTextArea.setValue(oPS.OutputString());

                oPS.ClearOutput();

              }

            }

            catch (exc) {

              alert(exc.message);

            }

          }

          else {

            alert(“Your Browser doesn’t support ActiveXObject”);

          }

        }

    </script>

  </head>

  <body class=”sapUiBody” role=”application” onLoad=”main()”>

    <div id=”content” />

  </body>

</html>

Here the result:

001.JPG

As you can see it is very easy to use PowerShell script inside UI5. On this way you have the possibility to combine the power of this worlds.

Enjoy it.

Cheers

Stefan

To report this post you need to login first.

Be the first to leave a comment

You must be Logged on to comment or reply to a post.

Leave a Reply