Jump to content

AnyBox PowerShell Module - Customizable WPF GUIs in one-line!


Recommended Posts

Posted (edited)

This looks really handy if you're creating GUIs for PowerShell scripts.

 

Website / Download (Install-Module -Name AnyBox) / Source Code / Changelog / Example Screenshots

 

Creating forms in Powershell can be tedious, from aligning the content just right to wiring up events. Thankfully, when it comes to GUIs for Powershell scripts, a simple message box or input box usually does the trick. The problem is that the not-so-built-in offerings for Powershell are extremely limited in (1) features and (2) customization.

 

Neither of these approaches are customizable beyond the essentials; they are focused purely on their limited functional. They're also not very Powershell-esque. If you want anything more, you'll have to create it yourself. A few options exist to make the creation of a custom form simpler (form designers), but the learning curve can be steep for a non-developer Powershell users (e.g., engineers, admins), and it is a tedious task even for the Powershell experts.

 

AnyBox was developed to satisfy both the need for simplicity and advanced customization when creating appealing WPF forms in Windows Powershell.

 

Examples (there are lots more if you visit the website link)

 

Show-AnyBox -Title 'MessageBoxDemo' -Message 'hello world' -FontSize 14 -ContentAlignment 'Center' -Buttons 'OK'

 

mJevck.jpg

 

Show-AnyBox -Title 'MessageBoxDemo' -Message 'hello world' -FontSize 14 -ContentAlignment 'Center' -Buttons 'Yes','No','Maybe?'

 

sobklx.png

 

Show-AnyBox -Title 'InputBoxDemo' -Prompts "what's your name?","what's your number?" -Buttons 'Cancel','Submit' -Comment '* responses are confidential'

 

1MXYAf.png

 

$job = Start-ThreadJob -ScriptBlock { Start-Sleep -Seconds 5 }

###

$anybox = New-Object AnyBox.AnyBox

$anybox.Message = 'A background job is running'
$anybox.Comment = 'This window will close when complete'

$anybox.WindowStyle = 'None'
$anybox.ContentAlignment = 'Center'
$anybox.Topmost = $true
$anybox.WindowStartupLocation = 'BottomRight'

$anybox.ProgressBar = $true
$anybox.While = { $job.State -eq 'Running' }

$anybox | Show-AnyBox

###

$null = $job | Receive-Job -Wait -AutoRemoveJob

 

fL6TXu.gif

 

Import-Module AnyBox

$anybox = New-Object AnyBox.AnyBox

$anybox.Prompts = @(
 # typical text prompt, but with default value.
 New-AnyBoxPrompt -InputType Text -Message "what's your name?" -DefaultValue 'donald'
 # typical text prompt, but with validation (must be all numeric).
 New-AnyBoxPrompt -InputType Text -Message "what's your number?" -ValidateScript { $_ -match '^[0-9]+$' }
 # sets are shown as drop-down lists.
 New-AnyBoxPrompt -InputType Text -Message "what's your favorite color?" -ValidateSet 'red','blue','green' -DefaultValue 'blue'
 # or sets of radio buttons.
 New-AnyBoxPrompt -InputType Text -Message "what's your favorite fruit?" -ValidateSet 'apple','banana','tomato?' -DefaultValue 'banana' -ShowSetAs Radio
 # date input.
 New-AnyBoxPrompt -InputType Date -Message "what's your birthday?" -DefaultValue '1970-01-01'
 # secure string input.
 New-AnyBoxPrompt -InputType Password -Message "what's your SSN?"
 # file input
 New-AnyBoxPrompt -InputType FileOpen -Message "Upload supporting documents:"
 # link input
 New-AnyBoxPrompt -InputType Link -Message "Terms & Conditions" -DefaultValue 'www.donaldmellenbruch.com'
 # checkbox (boolean) input.
 New-AnyBoxPrompt -InputType Checkbox -Message "I have read the terms & conditions" -DefaultValue $false
)

$anybox.ContentAlignment = 'Center'
$anybox.Buttons = 'Cancel','Submit'
$anybox.Icon = 'Question'

$anybox | Show-AnyBox

 

XQpBQb.png

Edited by Arthur
  • Thanks 1

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...