Primal Forms Primer III

Not being one to leave well enough alone, I added more bells and whistles to my form.

First, I wanted an Exit button. So I added a button and called it btnExit. I then typed EXIT in the Appearance,Text box. I then added this function to my script:

$btnExit_Click={
$formPingTest.Close()
}

Note that I used the New Name for my form here.

Next, I wanted to work on the output, so I added a RichTextBox from the Toolbox.

I left the name alone and sized it to fit the space.

I then added some code to my btnPing_Click function

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

$ping=Test-Connection -ComputerName $target
$statusbar1.Text="Pinging $target"
If ($ping) {
$FQDN = [system.net.dns]::GetHostEntry($target).HostName
If ($Error) {
$y = $error | select Exception
$e = $y -split (":")
$x = $e[2]
$Error.Clear()
$statusbar1.Text= $x
} Else
{ If ($FQDN){
$IPAddr = [system.net.dns]::GetHostEntry($target).addresslist
foreach ($addr in $IPAddr) {
$IP = $Addr.ipaddresstostring
$richTextBox1.text="FQDN: $FQDN `nIP: $IP"
}
}
Else {
$richTextBox1.text="Server is Off Line"
}
}
}

I added some Error handling and some code to get both the Fully Qualified Domain Name and the IP address of my target server. I then write that out to the RichTextBox like so:

$richTextBox1.text="FQDN: $FQDN `nIP: $IP"

the `n causes the IP address to appear on a new line. If I just wanted a tab between the FQDN and the IP I would have used `t. Note that there is NO Space between the `n and IP: , then I put the whole thing in quotes.

So now in my Status Bar I get the message, “Pinging Server” and in my Rich Text Box I get my results.

Advertisements

3 thoughts on “Primal Forms Primer III

  1. Greetings! This is my first visit to your blog! We are a collection of volunteers and starting a new project in a community in the same niche. Your blog provided us valuable information to work on. You have done a outstanding job!

  2. Greetings…First of all thanks for such a informative post.

    good one….i have a question…

    this script is for inputting single hostname…how can we use textbox to take the multiple hostnames input (one per line…using richtextbox and multi line options) and display the output in another richtext box…..

    i have been struggling to find on how to use primal forms (richtext box) to take the multiple hostnames as input.

    Any insight on this is very much appreciated.

    Thanks
    Azam

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