You've already forked SharedScripts
mirror of
https://github.com/jaapbrasser/SharedScripts.git
synced 2025-12-24 21:51:38 +02:00
61 lines
2.4 KiB
PowerShell
61 lines
2.4 KiB
PowerShell
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
|
|
#>
|
|
|
|
param(
|
|
[string] $Title = 'Example Title...',
|
|
[validateset('VB','Forms')]
|
|
[string] $GUIType = 'VB'
|
|
)
|
|
|
|
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)
|
|
}
|
|
}
|
|
'Forms' {
|
|
Add-Type -AssemblyName System.Windows.Forms
|
|
Add-Type -AssemblyName System.Drawing
|
|
$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:FormInputText=$FormInput.Text;$Form.Close()})
|
|
|
|
$Form.Controls.Add($FormText)
|
|
$Form.Controls.Add($FormInput)
|
|
$Form.Controls.Add($FormOKButton)
|
|
$Form.ShowDialog() | ForEach-Object {
|
|
[System.Windows.Forms.MessageBox]::Show([convert]::ToBase64String([char[]]$FormInputText),$Title) | Out-Null
|
|
}
|
|
}
|
|
default {
|
|
}
|
|
}
|
|
} |