Skip to Content

Hello community,

Windows PowerShell is a mix of command-line shell and scripting language. You find more Information about PowerShell here and here.

With the free COM library ActiveXPosh.dll from SAPIEN you can also use PowerShell inside ABAP.

Here an example how to get all services and its state.

  Program zPSTest.

      Type-Pools OLE2 .

      Constants OUTPUT_CONSOLE Type i Value 0.
      Constants OUTPUT_WINDOW Type i Value 1.
      Constants OUTPUT_BUFFER Type i Value 2.

      Data PS Type OLE2_OBJECT.
      Data Result Type i.
      Data strResult Type String.
      Data tabResult Type Table Of String.
      Data cmd Type String.

      Create Object PS 'SAPIEN.ActiveXPoSHV3'.
      If sy-subrc  0 Or PS-Handle = 0 Or PS-Type  'OLE2'.

      Call Method Of PS 'Init' = Result Exporting #1 = 0.
      If Result  0.
        Free Object PS.

      Call Method Of PS 'IsPowerShellInstalled' = Result.
      If Result = 0.
        Free Object PS.

      Set Property Of PS 'OutputMode' = OUTPUT_BUFFER.

      cmd = `Get-WmiObject -class Win32_Service | `.
      cmd = cmd &&  `Format-Table -property Name,State`.

      Call Method Of PS 'Execute' Exporting #1 = cmd.
      Call Method Of PS 'OutputString' = strResult.

      Split strResult At cl_abap_char_utilities=>cr_lf
        Into Table tabResult.

      Loop At tabResult Into strResult.
        Write: / strResult.

      Free Object PS.


You can use with PowerShell all dotNET and Windows standard libraries. On this way you can extend your possibilities.


To report this post you need to login first.

1 Comment

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

Leave a Reply