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-09 17:01:32 +02:00
|
|
|
[validateset('VB')]
|
|
|
|
|
[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:02:09 +02:00
|
|
|
'Windows.Forms' {
|
|
|
|
|
$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"
|
|
|
|
|
}
|
|
|
|
|
$FormOKButton.Add_Click({$Script:userInput=$FormInput.Text;$Form.Close()})
|
|
|
|
|
|
|
|
|
|
$Form.Controls.Add($FormText)
|
|
|
|
|
$Form.Controls.Add($FormInput)
|
|
|
|
|
$Form.Controls.Add($FormOKButton)
|
|
|
|
|
$Form.ShowDialog()
|
|
|
|
|
# | ForEach-Object {
|
|
|
|
|
# [convert]::ToBase64String([char[]]$_)
|
|
|
|
|
# }
|
|
|
|
|
}
|
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
|
|
|
}
|