Tuesday, February 18, 2014

Powershell and GUI : Button element

 

 Buttons

18-02-2014 16-25-39

 

One of the main component of any GUI application are buttons. Without Buttons, no GUI applications seems completed.

In my GUI application I use button a lot.

In today’s post we are going to see the basic functionality of the Button element.

Today we are going to cover only the “Click” event of the button. These “Click” event triggers when user press the button.

Let’s get started.

 

Note: I am using “Sapien PowerShell Studio 2012”   for creating GUI’s, you can also download the trial version of it for use and testing. It doesn’t matter which IDE you have used, concept are same everywhere.

1.       Open PowerShell studio 2012.

2.       Click on “New” and click on “New Form”

3.       18-02-2014 16-17-18

4.       Choose Empty Form and “Click on Select”.

5.       18-02-2014 16-17-31

6.       Now from the “Toolbox Panel”, click on “Label” and drop it on the blank form.

7.       18-02-2014 16-18-13

8.       Click on “Label” properties and change the following.

a.       Label’s Text to = “This is  a label”

b.      Design to = “labelmy”

9.       18-02-2014 16-19-55

10.   Now drag “Button” from the control pane and drop it on a form.

11.   18-02-2014 16-19-55

12.   Now  double click on “Button” and it will open the script pane,

13.   And you can see the Button name and a click method

14.   18-02-2014 16-20-32

$button1_Click={

       #TODO: Place custom script here

      

      

      

15.               }

18-02-2014 16-42-21

16.   $button1 is the name of our button and Click is a click method.

17.   Now let’s make this button do something.

18.    I have added the below line in the button click method

a.       $labelmy.Text = 'Oh my God!! Button is pressesd.'

19.   18-02-2014 16-22-03

20.   So when we press the button, our label text “This is a Label” will be changed to “'Oh my God!! Button is pressesd.'

21.   Let’s see that.

22.   Go back to form and click on “Run File” or press “Ctrl + F5”

23.   18-02-2014 16-22-19

24.   And when the form run, click on the button. And you will see that text of label is changed.

25.   18-02-2014 16-22-54

26.   Now let’s add some more fun.

27.   I have added the one more line of code and change the text for the label.

 

 

28.   18-02-2014 16-23-58

$button1_Click={

       #TODO: Place custom script here

      

       $labelmy.Text = 'Notepad! will be opened.'

       Start-Process 'notepad.exe'

      

29.               }

30.   Now, when we click on our button, the text of our label will change and it will open a notepad too.

31.   Run the form again and click on “button”

32.   And you can see that text is changed and a new notepad window is opened.

33.   18-02-2014 16-24-41

 

That’s all for now.

See you in my next blog posts.

 

Regards

clip_image017 clip_image018 clip_image019 clip_image020  clip_image021Aman Dhally

 

Friday, February 14, 2014

Part – 5 :PowerShell and DHCP : Getting Information on leased IP Addresses

 

 

Part – 1 : PowerShell and DHCP : Installing DHCP Server Role on Server 2012

Part – 2 :PowerShell and DHCP : DHCP Post-Install Configuration

Part – 3 :PowerShell and DHCP :  Configuring the DHCP Scope

Part – 4 :PowerShell and DHCP :   Setting DHCP server’s “Server Options”

 

 

Information and Reporting on DHCP Server.

In my previous post we had configured DHCP server’s “Server Options”.

Now our basic DHCP server is fully functional and providing the IP address to the dhcp clients.

Our next step is gathering information of the DHCP clients and the IP addresses leased by the server.

 

Check DHCP server Statistics

To get the quick statistics of the DHCP server, we can use the                                                         Get-DhcpServerv4Statistics” cmdlet and it will show us the quick statistics of the server.  

In these statistics you can see the total number of used and free IP address available.

 

clip_image001[4]

 

IP Address leases

To check the leased IP address those are given to the DHCP clients by DHCP server, we can use the “Get-DhcpServerv4Lease” cmdlet.

To use this cmdlet we have to use –ScopeID parameter. In our case ,our scope id is “192.168.1.0”

Get-DhcpServerv4Lease -ScopeId 192.168.1.0  -AllLeases

clip_image003[4]

clip_image005[4]

 

 

Getting list of available free IP Addresses

 

To know about next available free IP Address we can use                                                   Get-DhcpServerv4FreeIPAddresscmdlet.

Just run the cmdlet with –scopeID parameter and if you want to know the list 10, or 50 next of available free IP then you can use the – NumAddress parameter.

By running the below command we can see the next 10 available free IP addresses for the scope id of 192.168.1.0

Get-DhcpServerv4FreeIPAddress -ScopeId 192.168.1.0 -NumAddress 10

clip_image006[4]

 

That’s all for now. See you in our next blog post.

Regards

Aman Dhally

clip_image017 clip_image018 clip_image019 clip_image020  clip_image021

Monday, February 10, 2014

Part-4 PowerShell and DHCP: Setting DHCP server’s “Server Options”

 

 

Part – 1 : PowerShell and DHCP : Installing DHCP Server Role on Server 2012

Part – 2 :PowerShell and DHCP : DHCP Post-Install Configuration

Part – 3 :PowerShell and DHCP :  Configuring the DHCP Scope

 

In my previous post on “DHCP” article series, we had configure the “DHCP Scope” for DHCP server. Now it is time to set the “Sever Options” for the DHCP server.  

We are going to set the below server options.

S.No

OptionID

Description

1

6

DNS Server

2

3

 Gateway Address

3

15

DNS Suffix

 

Setting Server Options

We have to use the “Set-DhcpServerv4OptionValue” cmdlet to set server options for the DHCP Server. In this cmdlet we have to use the “OptionID” and it’s “Value” parameters mainly.

Open DHCP manager from tools and you can see that there is no “Server Options” are configured yet.

clip_image002

 

Run, “ipconfig /all on client machine and you can see, there is NO entries for, Gateway, Connection specific DNS Suffix and DNS Server ..

clip_image004

 

Setting DNS Server

Let’s set the DNS Server option first, the OptionID for DNS server is 6 ,  I am setting , 202.56.215.55  as a DNS Server.

Set-DhcpServerv4OptionValue -OptionId 6 -Value 202.56.215.55

clip_image006

 

You can also set multiple DNS server by providing multiple comma separated values.

Set-DhcpServerv4OptionValue -OptionId 6 -Value 202.56.215.55 , 202.56.215.54 , 8.8.8.8

clip_image008

 

Setting Gateway

The option ID for gateway is 3, I am setting the value 192.168.1.99 as a gateway address.

Set-DhcpServerv4OptionValue -OptionId 3 -Value 192.168.1.66

clip_image009

 

Setting DNS Suffix

The OptionID for DNS Suffix is 15

I am setting my website domain name a DNS suffix.

clip_image010

 

DHCP Manager

Now open DHCP server manager and click on “Server Options” and you will see all of our entries which we configured and set by PowerShell are there.

clip_image012

 

Testing

It’s time to test the configuration, Now, do the following on your client machine

1.       Run “Ipconfig /release

2.       Run “Ipconfig /renew

3.       Run “Ipconfig /all

Here you go, you can see all of our configured setting there.

clip_image014

 

That’s all for now. See you in my next blog article.

 

Regards

Aman Dhally

clip_image017 clip_image018 clip_image019 clip_image020  clip_image021

Thursday, February 6, 2014

PowerShell Application : Numerology Application created using PowerShell

 

clip_image002

 

Don’t call me insane, and please don’t use the words “WTF!”, “Shit” etc. I knew, PowerShell and numerology sound very insane.

I know, I know, PowerShell is for IT guys, Admins , developers, but, it is scripting language, we can use is to easy and other life.

Download Link : https://dl.dropboxusercontent.com/u/17858935/Numerology.zip

 

Background

 

One of my friend is a numerologist, he was facing some problem and asked me if I am able to help him. The issue which he was facing was to convert the name of his clients to numbers, he has to do the manually . That’s what he use to do.

For example you name is Aman and you want to know about your ruling number and planet

Alphabet

Position of Alphabet in English Letter

A

1

M

4

A

1

N

5

 

So the Number for Aman is = 1+4+1+5 = 11 as we have only 9 planets, we have to add 11 to 1+1 again and we got the ruling number 2.

Now if you name is more complex than mine, he is going to spent a decent amount of time to add it.

Solution

 

I have created a simple PowerShell GUI for him, so that he just need to type the name of the user it to it and click on calculate button, and he got the ruling number of the user along with him ruling planet.

 

How to use it

Download the zip file from this link : https://dl.dropboxusercontent.com/u/17858935/Numerology.zip

This zip file contain, Images those are used in the GUI, a PowerShell source file and an executable file.

To open the numerology PowerShell application.

Double click on “Numerology.exe”

 

clip_image003

Type you name and click on calculate. That’s all.

clip_image005

 

 

I learned

Open the PowerShell file,  and you can see a good example of using arrays and the if logic.

 

Special thanks

To all “PowerShell MVPs” who helped me when I stuck at a small script logic.

 

I hope you will enjoy this.

 

Regards

Aman Dhally

 

clip_image017 clip_image018 clip_image019 clip_image020  clip_image021