View Full Version : Is it possible to return the results of a poweshell command from an rsp page?

2016-07-13, 14:04

I recently had a request to serve up results of a powershell command from an rsp page.
I wasn't sure it its possible, so I thought I would ask if anyone had tried.

First request is just a simple list of all services on a given server.

PowerShell.exe Get-Service -ComputerName myserver



2016-07-13, 16:34
Hi Herb,

on way is to instantiate the PowerShell object as a .Net object -- check out Doug Hennigs article on using PowerShell in VFP, p.33: http://doughennig.com/papers/Pub/PowerShell.pdf.I don't know if wwDotNetBridge, which it uses, will work in Lianja, but there's a good chance it will. If it does, this would give you the opportunity to make a dynamic application with a list of the scripts or cmdlets or whatever.

The alternative is to run with the run command in Lianja (in a VFP code section of the .rsp) and generate a log file output and use that to display or parse/display.


2016-07-13, 20:13
Hi Hank,

My thought was something along the lines of

Run "PowerShell.exe Get-Service | Export-Csv c:\psoutput\test.csv" - which works in the desktop.

But I recall Barry telling us to create tempfile for rsp pages.

Like in the image example:

// Look up an employee
seek "Smith"

// Create a unique temporary name (guaranteed uniqueness across concurrent users in a network)
m_tmpnam = tmpnam()

// Extract the photo from the database and write it to the temporary file

// Generate the base64 encoded contents as an IMG tag and output into the HTML5
base64_encode_file(m_tmpnam, objectType(photo), "100px", "100px")

// Don't forget to remove the temporary file
erase &m_tmpnam

So - I'm thinking if I want to use an RSP page, I probably need to output the file to m_tmpnam.
But I will play around with it.



2016-07-13, 21:03
Hi Herb,

Yes because multiple requests can be running concurrently.