call a ps1 script and use variables

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

call a ps1 script and use variables

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

Hello,

I create a button on my test.psf.

Code: Select all

$buttonZertifikatErzeugen_Click={
	#TODO: Place custom script here
	#run CertExtServer16.ps1 script
	Invoke-CertExServer16_ps1
}
insde my test.psf i use a variable $mytest = "Test1" how i can use that variable "$mytest" inside the that CertExServer16_ps1 script? What i need wrote that i can use that variable "$mytest" from test.psf inside my ps1 script who i call?

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

Re: call a ps1 script and use variables

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

You have to pass the variable as a parameter to the script you want to use it in.

Be aware that "scope" may be an issue.

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

Re: call a ps1 script and use variables

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

How i can pass it? Could you tell me an example please.
And what means "scope my be an issue"?

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

Re: call a ps1 script and use variables

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

You use a Param statement to pass variables to a sript. Plewse take the time to learn basic PowerShell. Using parameters will be explained in detail. YOu can also use the links I posted. There are articles on how to pass and use variables in forms.

Scope is a fundamental concept in all programming and computing. In PowerShell it is documented in the help.

Start with:
help about_scopes

Post Reply