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.
"-Begin-----------------------------------------------------------------
Program zPSTest.
"-TypePools---------------------------------------------------------
Type-Pools OLE2 .
"-Constants--------------------------------------------------------
Constants OUTPUT_CONSOLE Type i Value 0.
Constants OUTPUT_WINDOW Type i Value 1.
Constants OUTPUT_BUFFER Type i Value 2.
"-Variables---------------------------------------------------------
Data PS Type OLE2_OBJECT.
Data Result Type i Value 0.
Data strResult Type String Value ''.
Data tabResult Type Table Of String.
"-Main--------------------------------------------------------------
Create Object PS 'SAPIEN.ActiveXPoSH'.
If sy-subrc = 0 And PS-Handle <> 0 And PS-Type = 'OLE2'.
Call Method Of PS 'Init' = Result Exporting #1 = 0.
If Result = 0.
Call Method Of PS 'IsPowerShellInstalled' = Result.
If Result <> 0.
Set Property Of PS 'OutputMode' = OUTPUT_BUFFER.
Call Method Of PS 'Execute' Exporting
#1 = 'Get-WmiObject -class Win32_Service | Format-Table -property Name,State'.
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.
EndLoop.
EndIf.
EndIf.
Free Object PS.
EndIf.
"-End-------------------------------------------------------------------
You can use with PowerShell all dotNET and Windows standard libraries. On this way you can extend your possibilities.
Cheers
Stefan





