get output of a ps1

Ask questions about creating Graphical User Interfaces (GUI) in PowerShell and using WinForms controls.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Post Reply
klarlichter
Posts: 40
Joined: Tue Nov 19, 2019 1:17 am

get output of a ps1

Post by klarlichter » Sun Nov 24, 2019 1:38 pm

Hello,

i create action on button click: Invoke-CertExServer16_ps1
i also place there a function to open another form: Show-outputPS1Box_psf

togehter it looks like:

Code: Select all

$buttonZertifikatErzeugen_Click={
	#TODO: Place custom script here
	#run CertExtServer16.ps1 script
	Invoke-CertExServer16_ps1
	Show-outputPS1Box_psf
}
How it is possible to show the output of invoke action on show-outputPS1Box_psf?

Hope someone can help.

jvierra
Posts: 14000
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: get output of a ps1

Post by jvierra » Sun Nov 24, 2019 1:53 pm

You will have to capture the output and pass it as a parameter to the "show" script.

klarlichter
Posts: 40
Joined: Tue Nov 19, 2019 1:17 am

Re: get output of a ps1

Post by klarlichter » Sun Nov 24, 2019 1:55 pm

How i can caputre that? and how to pass it?

Caputre not working like:

Code: Select all

$mycommand = Invoke-CertExServer16_ps1 | Out-String

jvierra
Posts: 14000
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: get output of a ps1

Post by jvierra » Sun Nov 24, 2019 2:01 pm

Without some basic understanding of how to use PowerShell all of this will be very difficult for you.

Here is a free book that will give you the background that you need to use PowerShell with PowerShell Studio.
https://www.sapien.com/books_training/W ... werShell-4

You can also find answers and examples here: https://info.sapien.com/index.php/guis

The left menu contains many resources for learning how to use PSS and Forms.

There are many videos here that can help you with PowerShell, PowerShell Studio and Forms: https://www.youtube.com/c/SAPIENTech

klarlichter
Posts: 40
Joined: Tue Nov 19, 2019 1:17 am

Re: get output of a ps1

Post by klarlichter » Sun Nov 24, 2019 2:04 pm

Hello,
i am proud to get some code working and i willing to lern and also review your sources.
But is it possible that you can post a example how i can pass that?
I mean how to caputre and show? It would be amazing.

klarlichter
Posts: 40
Joined: Tue Nov 19, 2019 1:17 am

Re: get output of a ps1

Post by klarlichter » Sun Nov 24, 2019 2:11 pm

If i let run my example

$textbox1.Text = ipconfig /all | Out-String
I see that output inside textbox

If I let run $textbox1.Text = Invoke-CertExServer16_ps1 | Out-String i cant see that output ... i only can see inde debug output inside of powershell studio the output :(

jvierra
Posts: 14000
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: get output of a ps1

Post by jvierra » Sun Nov 24, 2019 2:20 pm

You cannot send output from a form. You must access one of the provided variables that contain the data from the form.

Again. Their are articles in the info center that describe ow to use this in detail with examples. Learning how to use the info center will provide you with and excellent resource while learning PowerShell and PowerShell Studio,

klarlichter
Posts: 40
Joined: Tue Nov 19, 2019 1:17 am

Re: get output of a ps1

Post by klarlichter » Sun Nov 24, 2019 3:55 pm

Hello,

if i try that

example1:

Code: Select all

$buttonZertifikatErzeugen_Click={
	#TODO: Place custom script here
	$textbox1.Text = Invoke-CertExServer16_ps1 $contactEmail.Text $pfxPassword.Text | Out-String
}
It should normally display that output below on my textbox. (after press that button)

But it not display any. I try with simple command:

example2:

Code: Select all

$buttonZertifikatErzeugen_Click={
	#TODO: Place custom script here
$textbox1.Text = ipconfig /all | Out-String
}
and thats working. Wht it is only working with example 2 and not with example 1?

It might be happen because on example 1 i exectute a script from prject and on example 2 i exectute a command direct? Is that right?
If yes how i can get that output about that script who i exectute from that project folder?

jvierra
Posts: 14000
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: get output of a ps1

Post by jvierra » Sun Nov 24, 2019 4:06 pm

klarlichter wrote:
Sun Nov 24, 2019 3:55 pm

and thats working. Wht it is only working with example 2 and not with example 1?
As I noted - you cannot output from a form to anything. It is not possible. You must transfer data from a form through a variable.

Please see the blog posts and articles on passing values between forms. They are listed on the left menu in the info center.

klarlichter
Posts: 40
Joined: Tue Nov 19, 2019 1:17 am

Re: get output of a ps1

Post by klarlichter » Sun Nov 24, 2019 4:08 pm

Hi, i think now we get a miss - understanding.

How I pass a variable from one to another form i understood now. :)

As you can see my example 2 working as I told.

My example 1 not working.
You want to tell that i need save the output of my PS1 script into a variable and then pass them back to form? Is it right?

Post Reply