1. RamanaRao Nandigam
  2. PowerBuilder
  3. Friday, 12 August 2022 07:15 AM UTC

I don't know how to call powershell script from powerbuilder. Some one please help

 

Thanks

 

 

René Ullrich Accepted Answer Pending Moderation
  1. Friday, 12 August 2022 08:11 AM UTC
  2. PowerBuilder
  3. # 1

You could simple run powershell.exe from PowerBuilder.

e.g.

Run ("powershell.exe  -command 'hello';start-sleep 10")
Comment
  1. RamanaRao Nandigam
  2. Friday, 12 August 2022 10:27 AM UTC
thank you @Rene

My case I want to run aws powershell command and want to read output
  1. Helpful
  1. Roland Smith
  2. Friday, 12 August 2022 12:50 PM UTC
The Run function doesn't wait for the external program to finish. My RunAndWait example does and also has the option to capture output.

https://www.topwizprogramming.com/freecode_runandwait.html

  1. Helpful 3
  1. Steen Jakobsen
  2. Wednesday, 17 August 2022 06:42 AM UTC
I use this and it works GREAT.
  1. Helpful
There are no comments made yet.
Miguel Leeuwe Accepted Answer Pending Moderation
  1. Friday, 12 August 2022 12:44 PM UTC
  2. PowerBuilder
  3. # 2

Have a look at https://community.appeon.com/index.php/qna/q-a/error-checking-if-outlook-exe-process-is-running-with-m365-apps-for-enterprise-outlook-application 

Do a search on that page for "wbemscripting", I'm a noob on this, but it might enable you to run powershell commands?

This might also be interesting: https://stackoverflow.com/questions/64084420/vba-wscript-shell-executing-a-powershell-command 

(hopefully).

regards,

MiguelL

Comment
There are no comments made yet.
RamanaRao Nandigam Accepted Answer Pending Moderation
  1. Friday, 12 August 2022 15:41 PM UTC
  2. PowerBuilder
  3. # 3

Run (.....cmd)

The above sudo will run powershell command but not return anything. Run function return 0 or 1. But, we need data that we getting from command.

 

Detail:-

Run ("powershell.exe  -command Set-Location 'C:\'; mkdir .\Test -ea 0; "some command it will return some output json here";)

The above code will create test folder in C drive and get some json data. Here, Ineed json data, but run will return only 0 or 1. 

anyone knows how return Json data?

 

 

Comment
  1. René Ullrich
  2. Monday, 15 August 2022 07:16 AM UTC
You could export the data you need to a file in PowerShell script and read it from Powerbuilder.

I'm not a PowerShell expert, but maybe this can help you: https://stackoverflow.com/questions/22275724/how-to-save-a-json-object-to-a-file-using-powershell
  1. Helpful
There are no comments made yet.
Berka Frenfert Accepted Answer Pending Moderation
  1. Tuesday, 16 August 2022 08:21 AM UTC
  2. PowerBuilder
  3. # 4

Just in case you like to use dirty quick work with cmd then following might be useful. This sample code sends email through Powershell.

 I suggest the example that Roland Smith talks about is better way.

String psPath = "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe"
Integer li_FileNum
String theCmd

li_FileNum = FileOpen("C:\Temp\cmd.ps1", LineMode!, Write!, LockWrite!, Replace!)

theCmd = "$EmailFrom = ~"" + SendFrom.Text + "~""
FileWrite(li_FileNum, theCmd)

theCmd = "$EmailTo = ~"" + SendTo.Text + "~""
FileWrite(li_FileNum, theCmd)

theCmd = "$Subject = ~""+Subject.Text+"~""
FileWrite(li_FileNum, theCmd)

theCmd = "$Body = ~""+ Msg.Text + "~"" 
FileWrite(li_FileNum, theCmd)

theCmd = "$SMTPServer = ~"smtp.gmail.com~""
FileWrite(li_FileNum, theCmd)

theCmd = "$SMTPClient = New-Object Net.Mail.SmtpClient($SmtpServer, 587)"
FileWrite(li_FileNum, theCmd)

theCmd = "$SMTPClient.EnableSsl = $true"
FileWrite(li_FileNum, theCmd)

theCmd = "$SMTPClient.Credentials = New-Object System.Net.NetworkCredential(~"fartonheart@gmail.com~", ~"goldplated123~");"
FileWrite(li_FileNum, theCmd)

//theCmd = "$emailattachment = ~"c:\temp\datawindow.pdf~""
//FileWrite(li_FileNum, theCmd)
//
//theCmd = "$attachment = New-Object System.Net.Mail.Attachment($emailattachment, ~'text/plain~')"
//FileWrite(li_FileNum, theCmd)
//
//theCmd = "$Attachments.Add($attachment)"
//FileWrite(li_FileNum, theCmd)
//
theCmd = "$IsBodyHTML = $false"
FileWrite(li_FileNum, theCmd)

theCmd = "$SMTPClient.Send($EmailFrom, $EmailTo, $Subject, $Body)"
FileWrite(li_FileNum, theCmd)

FileClose(li_FileNum)

int li_rc 
string ls_command 
string ls_directory 
ls_directory = "C:\temp"
ls_command = 'C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -NoProfile -ExecutionPolicy Bypass -Command "&' 
ls_command += " '" + ls_directory + "\cmd.ps1' " 
li_rc = Run ( ls_command, Minimized! )
Comment
  1. RamanaRao Nandigam
  2. Tuesday, 16 August 2022 12:12 PM UTC
this will create required command and sent. But I have to read out put from command. The above example there is no read operation.

I want read output of



output = Run (cmd..)

I want output. But run will return either 0 or 1.

  1. Helpful
  1. Roland Smith
  2. Tuesday, 16 August 2022 19:58 PM UTC
Did you try my RunAndWait app? It has a function RunAndCapture that will run the program, wait for it to finish, and capture the console output.
  1. Helpful
  1. Berka Frenfert
  2. Wednesday, 17 August 2022 07:43 AM UTC
Hi Rene, Thanks for advise. I used the password in 1998 and always use it when i dont care about it.:) The code sample was written 3 years ago.
  1. Helpful
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.