Keep it as a reference base script first "# Tab Merge Both # Requires PowerShell 5.x; ensure STA for WinForms/Clipboard if ($Host.Runspace.ApartmentState -ne 'STA') { powershell -sta -nologo -noprofile -command $PSCommandPath exit } Add-Ty
Here's your provided PowerShell script formatted for clarity and easy reference, encapsulated in a code block. This script creates a GUI application using Windows Forms that allows users to take notes and manage email templates for a help desk.
```powershell
# Tab Merge Both
# Requires PowerShell 5.x; ensure STA for WinForms/Clipboard
if ($Host.Runspace.ApartmentState -ne 'STA') {
powershell -sta -nologo -noprofile -command $PSCommandPath
exit
}
Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.Drawing
# -----------------------------
# Layout constants (client area)
# -----------------------------
$clientWidth = 1209
$clientHeight = 727
$pad = 20
$bottomY = $clientHeight - 48 # button row Y
# -----------------------------
# Form (96 DPI, white background)
# -----------------------------
$form = New-Object System.Windows.Forms.Form
$form.Text = 'Service Desk Helper'
$form.StartPosition = 'CenterScreen'
$form.TopMost = $true
$form.FormBorderStyle = 'FixedDialog' # Prevent resize
$form.MaximizeBox = $false
$form.ClientSize = New-Object System.Drawing.Size($clientWidth, $clientHeight)
$form.BackColor = [System.Drawing.Color]::White
$form.AutoScaleMode = 'Dpi'
# -----------------------------
# Tab control
# -----------------------------
$tabs = New-Object System.Windows.Forms.TabControl
$tabs.Dock = 'Fill'
$tabs.Font = New-Object System.Drawing.Font('Segoe UI', 10)
$form.Controls.Add($tabs)
$tabNote = New-Object System.Windows.Forms.TabPage
$tabNote.Text = 'Service Desk Note Taker'
$tabNote.BackColor = [System.Drawing.Color]::White
$tabEmail = New-Object System.Windows.Forms.TabPage
$tabEmail.Text = 'Email Templates'
$tabEmail.BackColor = [System.Drawing.Color]::White
$tabs.TabPages.AddRange(@($tabNote, $tabEmail))
# ============================================================
# TAB 1: Service Desk Note Taker (Name, Issue, Email + buttons)
# ============================================================
# Labels
$lblName = New-Object System.Windows.Forms.Label
$lblName.Text = 'Name'
$lblName.Location = New-Object System.Drawing.Point($pad, $pad)
$lblName.AutoSize = $true
$lblName.Font = New-Object System.Drawing.Font('Segoe UI', 10)
$lblIssue = New-Object System.Windows.Forms.Label
$lblIssue.Text = 'Issue'
$lblIssue.Location = New-Object System.Drawing.Point($pad, 60)
$lblIssue.AutoSize = $true
$lblIssue.Font = New-Object System.Drawing.Font('Segoe UI', 10)
$lblEmail = New-Object System.Windows.Forms.Label
$lblEmail.Text = 'Email'
$lblEmail.Location = New-Object System.Drawing.Point($pad, 410)
$lblEmail.AutoSize = $true
$lblEmail.Font = New-Object System.Drawing.Font('Segoe UI', 10)
# TextBoxes
$tbName = New-Object System.Windows.Forms.TextBox
$tbName.Location = New-Object System.Drawing.Point(120, $pad - 2)
$tbName.Size = New-Object System.Drawing.Size($clientWidth - 120 - $pad, 28)
$tbName.Font = New-Object System.Drawing.Font('Segoe UI', 10)
$tbName.BackColor = [System.Drawing.Color]::White
$tbName.ForeColor = [System.Drawing.Color]::Black
$tbName.Anchor = [System.Windows.Forms.AnchorStyles]::Top -bor `
[System.Windows.Forms.AnchorStyles]::Left -bor `
[System.Windows.Forms.AnchorStyles]::Right
$tbIssue = New-Object System.Windows.Forms.TextBox
$tbIssue.Location = New-Object System.Drawing.Point(120, 56)
$tbIssue.Size = New-Object System.Drawing.Size($clientWidth - 120 - $pad, 330)
$tbIssue.Multiline = $true
$tbIssue.ScrollBars = 'Vertical'
$tbIssue.Font = New-Object System.Drawing.Font('Segoe UI', 10)
$tbIssue.BackColor = [System.Drawing.Color]::White
$tbIssue.ForeColor = [System.Drawing.Color]::Black
$tbIssue.Anchor = [System.Windows.Forms.AnchorStyles]::Top -bor `
[System.Windows.Forms.AnchorStyles]::Left -bor `
[System.Windows.Forms.AnchorStyles]::Right
$tbEmail = New-Object System.Windows.Forms.TextBox
$tbEmail.Location = New-Object System.Drawing.Point(120, 406)
$tbEmail.Size = New-Object System.Drawing.Size($clientWidth - 120 - $pad, 28)
$tbEmail.Font = New-Object System.Drawing.Font('Segoe UI', 10)
$tbEmail.BackColor = [System.Drawing.Color]::White
$tbEmail.ForeColor = [System.Drawing.Color]::Black
$tbEmail.Anchor = [System.Windows.Forms.AnchorStyles]::Top -bor `
[System.Windows.Forms.AnchorStyles]::Left -bor `
[System.Windows.Forms.AnchorStyles]::Right
# Buttons (Copy, Clear, Close)
$btnCopyNote = New-Object System.Windows.Forms.Button
$btnCopyNote.Text = 'Copy'
$btnCopyNote.Font = New-Object System.Drawing.Font('Segoe UI', 10, [System.Drawing.FontStyle]::Bold)
$btnCopyNote.Size = New-Object System.Drawing.Size(120, 34)
$btnCopyNote.Location = New-Object System.Drawing.Point($pad, $bottomY)
$btnCopyNote.Anchor = [System.Windows.Forms.AnchorStyles]::Bottom -bor [System.Windows.Forms.AnchorStyles]::Left
$btnClearNote = New-Object System.Windows.Forms.Button
$btnClearNote.Text = 'Clear'
$btnClearNote.Font = New-Object System.Drawing.Font('Segoe UI', 10)
$btnClearNote.Size = New-Object System.Drawing.Size(120, 34)
$btnClearNote.Location = New-Object System.Drawing.Point($pad + 130, $bottomY)
$btnClearNote.Anchor = [System.Windows.Forms.AnchorStyles]::Bottom -bor [System.Windows.Forms.AnchorStyles]::Left
$btnCloseNote = New-Object System.Windows.Forms.Button
$btnCloseNote.Text = 'Close'
$btnCloseNote.Font = New-Object System.Drawing.Font('Segoe UI', 10)
$btnCloseNote.Size = New-Object System.Drawing.Size(120, 34)
$btnCloseNote.Location = New-Object System.Drawing.Point($clientWidth - $pad - 120, $bottomY)
$btnCloseNote.Anchor = [System.Windows.Forms.AnchorStyles]::Bottom -bor [System.Windows.Forms.AnchorStyles]::Right
# Copy logic (Tab 1)
$btnCopyNote.Add_Click({
$name = $tbName.Text.Trim()
$issue = $tbIssue.Text.Trim()
$email = $tbEmail.Text.Trim()
$note = "Name: $name`r`nEmail: $email`r`nIssue:`r`n$issue"
[System.Windows.Forms.Clipboard]::SetText($note, [System.Windows.Forms.TextDataFormat]::UnicodeText)
[System.Windows.Forms.MessageBox]::Show('Note copied to clipboard.', 'Copied') | Out-Null
})
# Clear logic (Tab 1)
$btnClearNote.Add_Click({
$tbName.Clear()
$tbIssue.Clear()
$tbEmail.Clear()
})
# Close logic (Tab 1)
$btnCloseNote.Add_Click({ $form.Close() })
# Add to tab
$tabNote.Controls.AddRange(@(
$lblName, $tbName,
$lblIssue, $tbIssue,
$lblEmail, $tbEmail,
$btnCopyNote, $btnClearNote, $btnCloseNote
))
# =========================================
# TAB 2: Email Templates (3 buttons + editor)
# =========================================
# Default templates
$tmplName = @"
Hello [User Name],
We are ready to assist you. Please confirm your availability for a remote session at a suitable date and time.
Regards,
Harinder Singh
"@
$tmplEmail1 = @"
Hello Team,
Thank you for reaching out. We'd like to assist with the query mentioned in the ticket. Could you please confirm your availability for a remote session?
Please share a suitable date and time, and we'll arrange the session accordingly.
Regards,
Harinder Singh
"@
$tmplEmail2 = @"
Dear [User Name],
This is a follow-up regarding your support request. Please advise a convenient time for a remote session so we can proceed.
Kind regards,
Harinder Singh
"@
# Template action buttons
$btnTmplName = New-Object System.Windows.Forms.Button
$btnTmplName.Text = 'Name'
$btnTmplName.Font = New-Object System.Drawing.Font('Segoe UI', 10, [System.Drawing.FontStyle]::Bold)
$btnTmplName.Size = New-Object System.Drawing.Size(120, 34)
$btnTmplName.Location = New-Object System.Drawing.Point($pad, $pad)
$btnTmplEmail1 = New-Object System.Windows.Forms.Button
$btnTmplEmail1.Text = 'Email 1'
$btnTmplEmail1.Font = New-Object System.Drawing.Font('Segoe UI', 10, [System.Drawing.FontStyle]::Bold)
$btnTmplEmail1.Size = New-Object System.Drawing.Size(120, 34)
$btnTmplEmail1.Location = New-Object System.Drawing.Point($pad + 130, $pad)
$btnTmplEmail2 = New-Object System.Windows.Forms.Button
$btnTmplEmail2.Text = 'Email 2'
$btnTmplEmail2.Font = New-Object System.Drawing.Font('Segoe UI', 10, [System.Drawing.FontStyle]::Bold)
$btnTmplEmail2.Size = New-Object System.Drawing.Size(120, 34)
$btnTmplEmail2.Location = New-Object System.Drawing.Point($pad + 260, $pad)
# Big editor box
$tbTemplate = New-Object System.Windows.Forms.TextBox
$tbTemplate.Multiline = $true
$tbTemplate.ScrollBars = 'Vertical'
$tbTemplate.Font = New-Object System.Drawing.Font('Segoe UI', 10)
$tbTemplate.BackColor = [System.Drawing.Color]::White
$tbTemplate.ForeColor = [System.Drawing.Color]::Black
$tbTemplate.Location = New-Object System.Drawing.Point($pad, 60)
$tbTemplate.Size = New-Object System.Drawing.Size($clientWidth - (2*$pad), $clientHeight - 60 - 70)
$tbTemplate.Anchor = [System.Windows.Forms.AnchorStyles]::Top -bor `
[System.Windows.Forms.AnchorStyles]::Left -bor `
[System.Windows.Forms.AnchorStyles]::Right -bor `
[System.Windows.Forms.AnchorStyles]::Bottom
# Buttons (Copy, Clear, Close) for Tab 2
$btnCopyEmail = New-Object System.Windows.Forms.Button
$btnCopyEmail.Text = 'Copy'
$btnCopyEmail.Font = New-Object System.Drawing.Font('Segoe UI', 10, [System.Drawing.FontStyle]::Bold)
$btnCopyEmail.Size = New-Object System.Drawing.Size(120, 34)
$btnCopyEmail.Location = New-Object System.Drawing.Point($pad, $bottomY)
$btnCopyEmail.Anchor = [System.Windows.Forms.AnchorStyles]::Bottom -bor [System.Windows.Forms.AnchorStyles]::Left
$btnClearEmail = New-Object System.Windows.Forms.Button
$btnClearEmail.Text = 'Clear'
$btnClearEmail.Font = New-Object System.Drawing.Font('Segoe UI', 10)
$btnClearEmail.Size = New-Object System.Drawing.Size(120, 34)
$btnClearEmail.Location = New-Object System.Drawing.Point($pad + 130, $bottomY)
$btnClearEmail.Anchor = [System.Windows.Forms.AnchorStyles]::Bottom -bor [System.Windows.Forms.AnchorStyles]::Left
$btnCloseEmail = New-Object System.Windows.Forms.Button
$btnCloseEmail.Text = 'Close'
$btnCloseEmail.Font = New-Object System.Drawing.Font('Segoe UI', 10)
$btnCloseEmail.Size = New-Object System.Drawing.Size(120, 34)
$btnCloseEmail.Location = New-Object System.Drawing.Point($clientWidth - $pad - 120, $bottomY)
$btnCloseEmail.Anchor = [System.Windows.Forms.AnchorStyles]::Bottom -bor [System.Windows.Forms.AnchorStyles]::Right
# Button actions to load templates
$btnTmplName.Add_Click({ $tbTemplate.Text = $tmplName })
$btnTmplEmail1.Add_Click({ $tbTemplate.Text = $tmplEmail1 })
$btnTmplEmail2.Add_Click({ $tbTemplate.Text = $tmplEmail2 })
# Copy logic (Tab 2)
$btnCopyEmail.Add_Click({
[System.Windows.Forms.Clipboard]::SetText($tbTemplate.Text, [System.Windows.Forms.TextDataFormat]::UnicodeText)
[System.Windows.Forms.MessageBox]::Show('Template copied to clipboard.', 'Copied') | Out-Null
})
# Clear logic (Tab 2)
$btnClearEmail.Add_Click({ $tbTemplate.Clear() })
# Close logic (Tab 2)
$btnCloseEmail.Add_Click({ $form.Close() })
# Add to tab
$tabEmail.Controls.AddRange(@(
$btnTmplName, $btnTmplEmail1, $btnTmplEmail2,
$tbTemplate,
$btnCopyEmail, $btnClearEmail, $btnCloseEmail
))
# Show dialog
[void]$form.ShowDialog()
```
This script provides a practical tool for help desk agents to gather notes and quickly access predefined email templates, enhancing communication efficiency. You can customize the email templates or modify UI elements as needed for your specific use case.


