Powershell Script – Wake on LAN utility Ver 1.0

Hello World,

Today’s post will demonstrate how you can “quickly” create a GUI around your powershell script.

Some time ago, I was working in an environment where free tools were not to be installed on production environment.   And, there was a need to have a tool to Wake on LAN the workstations.  The only option we had was to come up with a “creative” solution.   We thought that a powershell script could do this.

Note : Old Post republished from old web site


The Wake  On LAN (WOL)  Powershell function

I had no clue if this was possible or not.  I used my preferred search tool (i.e. google) to find some information about WOL and Powershell script.  I have found several blogs and posts about the possibility to create a Powershell script to wake on LAN workstations.  I’ve found on this page a code snippet that I would be able to use.

At this stage, we had half of the work done !  The code snippet we have found can be used from the command line.  To improve the user experience, we decided to build up a nice user interface around this code. 

Building the UI

The easiest way we have found so far to create Graphical user interface (GUI) for Powershell Script is to download and install the PrimalForm CE tool.  You will need to register but the Community Edition is Free to use.   Using the PrimalForm CE, you will be able to design the User Interface.  With PrimalForm, you will put toegether the graphical interface but no logic will be produced.  You will need to edit this code afterwards and create the piece of code that you want to execute.  

Click on picture for better resolution

When you are happy with your interface, you can export your project into a ps1 file.

Click on picture for better resolution


For illustration purposes, you can find a screenshot of the User interface we have created so far.

Click on picture for better resolution


Adding Code and logic behind the UI

At this stage, we have our User interface but there is no logic so far.  If you click on the “wake up” button,nothing will happen because there is no code associated to this event.  We will need to write this code.  To  do this,  you will need to edit the exported file (ps1) using Powershell ISE (a graphical interface to run and write powershell script – built in in the operating system but you might need to install it on Windows 2008 R2) or using notepad if you have no other alternative.

If you open the file, you will see that a lot of code is already present.  This code is used to generate the windows form you have build with PrimalForm.

 Click on picture for better resolution

In our simple example, we have to add the code to trigger an action when the user will be pressing the “Wake Up !”  button. In the script, you will need to locate the section marked as Generated Event Scripts Blocks, and simply add the code snippet  used to send the magic packet to the target computer and wake it up.  The code would look like something like this.

Click on picture for better resolution

You will need to test your application and ensure that the script is doing what it is suppose to do.

Using the script

Using the script is quite simple.  We have placed within a folder the script file and the image or images to be used with the User Interface.  Within the script, we have add a line of code that will ensure that the script will be using the location of script as working directory.  This means that you can copy the folder anywhere on your computer and the script will automatically use this location as the working directory and load the graphics (if any).

To be able to run the script, you have to ensure that the Powershell Execution Policy are configured correctly as well.

Note: We assume that the computer to wake up has been configured accordingly in order to accept the wake on Lan command and that the network card support Wake On Lan feature.

Future Versions ?

As mentioned in the title of this post, this simple (and sample) script is marked as Ver 1.0.  Indeed, the script is performing really a basic action. It will wake on LAN one computer at the time.   We might want to develop a version 2.0 of this utility.  The Version 2.0 will allow you to add and store information into an xml file.  The information will be Computer Name, IP Address and Mac Address.  You can store multiple entries within the XML file.  The script will then read the xml file and will display the content of it in a nice format where the user will be able to choose which computer to wake on LAN.

Final Notes

With this post, we have quickly demonstrate how to create a user interface around a powershell script.  We have used the PrimalForm CE tool to create the interface and we have then added the custom script needed to perform the required action.

Till Next time

See ya

Credits :  The original function for the WOL has been found at http://andrewmorgan.ie/2011/08/22/simple-wake-on-lan-powershell-module/


Leave a Reply