2019-08-09 16:59:33 +02:00
function ConvertTo-Base64GUIExample {
<#
. SYNOPSIS
Function to showcase some of the PowerShell GUI capabilities
. DESCRIPTION
This function contains various examples of using the GUI capabilities of both Windows PowerShell and PowerShell (Core) . This is inteded to be used as a reference for those interested in building basic GUIs with PowerShell
#>
2019-08-09 17:01:32 +02:00
param (
2019-08-11 22:02:47 +02:00
[ string ] $Title = 'Example Title...' ,
2019-08-11 22:08:32 +02:00
[ validateset ( 'VB' , 'Forms' ) ]
2019-08-09 17:01:32 +02:00
[ string ] $GUIType = 'VB'
)
2019-08-09 17:07:31 +02:00
switch ( $GUIType ) {
'VB' {
[ System.Reflection.Assembly ] :: LoadWithPartialName ( 'Microsoft.VisualBasic' ) | Out-Null
[ Microsoft.VisualBasic.Interaction ] :: InputBox ( " Let's convert this to base64 " , $Title , $null ) | ForEach-Object {
[ Microsoft.VisualBasic.Interaction ] :: MsgBox ( [ convert ] :: ToBase64String ( [ char[] ] $_ ) , 0 , $Title )
}
}
2019-08-11 22:08:32 +02:00
'Forms' {
2019-08-11 22:14:11 +02:00
Add-Type -AssemblyName System . Windows . Forms
Add-Type -AssemblyName System . Drawing
2019-08-11 22:02:09 +02:00
$Form = New-Object System . Windows . Forms . Form -Property @ {
Text = $Title
Size = New-Object System . Drawing . Size ( 300 , 150 )
StartPosition = " CenterScreen "
Topmost = $true
}
$FormText = New-Object System . Windows . Forms . Label -Property @ {
Location = New-Object System . Drawing . Size ( 10 , 20 )
Size = New-Object System . Drawing . Size ( 280 , 30 )
Text = " Let's convert this to base64 "
}
$FormInput = New-Object System . Windows . Forms . TextBox -Property @ {
Location = New-Object System . Drawing . Size ( 10 , 50 )
Size = New-Object System . Drawing . Size ( 260 , 20 )
}
$FormOKButton = New-Object System . Windows . Forms . Button -Property @ {
Location = New-Object System . Drawing . Size ( 130 , 75 )
Size = New-Object System . Drawing . Size ( 40 , 23 )
Text = " OK "
}
2019-08-11 22:04:01 +02:00
$FormOKButton . Add_Click ( { $Script:FormInputText = $FormInput . Text ; $Form . Close ( ) } )
2019-08-11 22:02:09 +02:00
$Form . Controls . Add ( $FormText )
$Form . Controls . Add ( $FormInput )
$Form . Controls . Add ( $FormOKButton )
2019-08-11 22:04:01 +02:00
$Form . ShowDialog ( ) | ForEach-Object {
2019-08-11 22:08:32 +02:00
[ System.Windows.Forms.MessageBox ] :: Show ( [ convert ] :: ToBase64String ( [ char[] ] $FormInputText ) , $Title ) | Out-Null
2019-08-11 22:04:01 +02:00
}
2019-08-11 22:02:09 +02:00
}
2019-08-09 17:07:31 +02:00
default {
2019-08-09 17:04:11 +02:00
}
2019-08-09 17:01:32 +02:00
}
2019-08-09 16:59:33 +02:00
}