cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Execute command from PowerShell

4,810

I have no experience with SAP, but I should create a PowerShell script. I've taken a look at the SAP community and found some examples like https://blogs.sap.com/2015/09/26/how-to-use-powershell-for-automated-login-to-sap/ which explain how to log on to the SAP GUI. In addition to that, I should be able to execute a command from CLI. The command is:

.\sapshcut -system=EHD -client=102 -user=myUserName -PW=myPass -maxgui -command="va03"

Is it possible to execute this command after the logon thru the PowerShell script?

Thanks

View Entire Topic
0 Likes

Hi Stefan,

thanks for the code, I tried but get an error when tried to create a $session with the following code:

$SapGuiAuto = [microsoft.visualbasic.Interaction]::GetObject("SAPGUI")

$application = Invoke-Method $SapGuiAuto "GetScriptingEngine"

$connection = Get-Property $application "Children" @(0)

$session = Get-Property $connection "Children" @(0)

It failed on the first line with the error message:

"Cannot create ActiveX component"

I research community and Internet articles and found that Visual Basic assembly needs to be loaded but even after I add this additional line of code still same error message.

Do I need to install additional SAP components to be able to create a session?

If it matters I'm using SAP NetWeaver (SAP GUI), Release 760 Final Release, File Version 7600.1.11.1160 Build 2065455 Patch Level 11.

Stefan-Schnell
Active Contributor
0 Likes

prusacv

Hello Vladimir,
sorry for my delayed reply. No it is not necessary to install an additional SAP component, all you need is the SAPFEWSE.OCX and this is part of the SAP GUI for Windows installation.
Best regards
Stefan