Today’s Bit of PowerShell Awesome – Primal Forms
I often find myself with more tools to check out than I have time to do the checking out. One of the tools that has been on my laundry list for a while was Primal Forms from Sapien. In a single word, this tool is “Awesome”.
From the site:
PrimalForms is a free GUI builder tool for PowerShell users. It edits and stores Windows Forms in a native XML format and generates PowerShell code on demand. Sample forms included.
It is important to note that it will not let you write PowerShell itself. It will however let you build a user interface for your scripts, and generate the PowerShell you need in order to make the GUI itself.
Here is a sample:
Cool, no? Here is what it looks like in action:
Woot! Actually, I do not have any snapshots running at present in my test environment, and did not want to leave one running for a few days for the demo. What is the script doing behind the scenes? Take a gander:
$findSnaps_OnClick {
$days_Old = $daysOld.Value
$richTextBox1.Text = "Connecting to VI Server…`n"
Get-Credential | Connect-VIServer -Server $vCenterHost.Text
$richTextBox1.Text += "Looking for snapshots older than $days_Old days old…`n"
$snapshots = Get-VM | Get-Snapshot | Where {$_.Created -lt (Get-Date).AddDays(-$days_Old) }
if ($snapshots){
$snapshots | %{
$VM = $_.VM.Name
$snapshot = $_.Name
$created = $_.Created
$richTextBox1.Text += "`nVM: $VM`nSnapshot: $snapshot`nCreated: $created"
} }
$richTextBox1.Text += "No snapshots found."
} } That is actually all of the logic I had to throw in there. Where is the rest? The form control, button, text box, etc were all generated by PrimalForms. The resulting code can be found here. The PrimalForms file for this can be found here.