Primal Forms Primer

I usually use HTA’s when I want to create a simple front end for my scripts, but I thought I would give PrimalForms a try for a project I am currently working on.

The first thing I found is that the good folks a Sapien have not gotten around to writing any documentation for this program. So you have to figure things out by looking at samples and guessing.

So , I thought I would write down what I find as I work my way through this to

1. Remind myself in the future

2. Help anybody out who is as clueless as I am.

If some of this is rudimentary or obvious to you, I apologize in advance. If I make any errors or make things more complicated than they need to be, please let me know.

So, the first thing I tried to do was make a form that would set the parameters for a script. BTW, I am using PrimalForms 2011. Seems easy enough. Open up Primal forms go to file new and select New, Form. I selected an Empty Form from the templates.

Next I went to the Toolbox on the left and picked a TextBox and placed it in my form. A new menu pops up on the right where you can set the properties of your new box. Down toward the bottom is Design, Name. Change this name from textbox1 to the name of the parameter you plan on entering. Like txtServerName, later this will become important.

Hopefully you have a working script that you want to use with this form.

Suppose you want to Ping a server.

You could use this Power Shell command to do that:

$ping=Test-Connection -ComputerName $target

So you need to define $target.

[string]$target=$txtServerName.Text #
$ping=Test-Connection -ComputerName $target

So go back to the form and add a Button from the toolbox. In the properties menu, change the name to btnPing in the Design, Name space and type Ping in Appearance, Text space.

On the left side of the form are two tabs. One called Designer and one called script.

Click on Script.

Here is where you paste in your script. Your script becomes a function here so give it a name. As I want it to execute when I press my ping button, I’ll call it btnPing_Click

Like this:

$btnPing_Click={
[string]$target=$txtServerName.Text

$ping=Test-Connection -ComputerName $target

}

Go back to the Designer tab, select your “Ping” button. In the Properties menu,

click the Lightning bolt at the top. In the very first box, Action, Click there will be a drop down box. Your new “function btnPing_Click should be there, select it and we are done for now. Save your form. I called mine TestPing.pff.  You should also take a look at:

Hey, Scripting Guy! How Can I Create a Windows Form Using Windows PowerShell and PrimalForms?

More tomorrow.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s