Although PowerShell is best suited for console applications there are times when a GUI interface just makes sense, however hand cranking PowerShell code to display a GUI seems almost anti-productive when we are used to rich IDE’s with WYSIWIG development available in other programming languages. Fortunately there are several 3rd party tools like, CodePlex projects like as well as many great data visualization scripts which reduce the amount of time to build GUIs in PowerShell. In this blog post we’ll look at another option for buidling GUIs, a free utility from called. To demonstrate Primal Forms, I thought it would be interesting to create a basic CRUD form for a SQL Server table, so I adapted the example on to PowerShell. Although the example uses the authors table in the sample pubs database, I can think of many real-world applications with tables used solely by sys admins to control user access or store configuration data about an application. In order to provide an interface to security and configuration tables a web front end could be developed, PowerShell scripts or cmdlets created or an MS Access front end could be used.

All true, but I think the use of PowerShell and a WinForm datagridview provides a light-weight alternative that is completely accessible to PowerShell savvy admins. Primal Forms is a simple IDE for building WinForms; if you’ve used Visual Studio, the form development feels similar. In the screenshot below I created a form with three controls: a dataGridView, and two buttons (reload and submit). Once you’ve created the form you can save the form definition in an XML format for later editing within Primal Forms.

Edition

Sapien Primalforms Community Edition

Primalforms ce

When you’re ready to create a PowerShell script, select Export to PowerShell. Primal Forms creates all the necessary PowerShell code for the WinForm and controls which you can save to a.ps1 file. In the example that follows, I’ve named the script dataGrid.ps1.

All that’s left to do is add event handling to the form load and various forms controls (buttons). Note the actual user of the PowerShell script does not need to have Primal Forms installed. Primal Forms simply generates 100% compliant PowerShell code for WinForms. Adding the event handling must be done in a text editor. Open the newly created dataGrid.ps1 file in your PowerShell script editor of choice. Primal Forms creates placeholders for the events. In this example the following TODO placeholders are generated.

Jan 13, 2012 A short video which describes why and how to create GUI based scripts using Windows Forms and SAPIEN PrimalForms.

German PowerShell GUI mit WindowsForms und Sapien PrimalForms Community Edition Deutsch. Jul 16, 2011 GUI Creation with PowerShell: The. But different feature sets) and the free PrimalForms Community Edition. If you liked this tutorial or had.

Tracey, I see you added a function called OnApplicationLoad. I have no such function (or maybe the new version of Primal forms generates this code). At first glance it looks like a problem with variable scope.

In my code I define the $bindingSource1, $dataAdapter, $serverName, $databaseName and $query variable as parent function level variables, so they are visible to the child functions. In your code it appears some of these variables are defined with OnApplicationLoad only. I would suggest starting with my code base and changing the database, query and server name variables.

Disclaimer The sample scripts are not supported under any Microsoft standard support program or service. The sample scripts are provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you.

In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.