I am going to use GUI with a button click to return an error level with a specific number. It returns the error level value just for $Auto_Button, and the GUI disappears when the script executed.
Add-Type -AssemblyName System.Windows.Forms $Font = New-Object System.Drawing.Font("Times New Roman",13)
$MainForm = New-Object System.Windows.Forms.Form
$MainForm.Text = "Process"
$MainForm.Width = 500
$MainForm.Height = 200
$MainForm.StartPosition = "CenterScreen"
$MainForm.BackColor = "#e2e2e2"
$Title = New-Object System.Windows.Forms.Label
$Title.Font = $Font
$Title.Text = "Which process do you want to choose?"
$Title.Location = New-Object System.Drawing.Size(100,30)
$Title.Size = New-Object System.Drawing.Size(500,30)
$MainForm.Controls.Add($Title)
$Auto_Button = {$MainForm.Close()}
Exit 10
$Manual_Button = $MainForm.Close()}
Exit 30
$Automatic = New-Object System.Windows.Forms.Button
$Automatic.Location = New-Object System.Drawing.Size(110,80)
$Automatic.Size = New-Object System.Drawing.Size(100,30)
$Automatic.Text = "Automatically"
$Automatic.Font = 'Microsoft Sans Serif,10'
$Automatic.BackColor = "#e47104"
$Automatic.Add_Click($Auto_Button)
$MainForm.Controls.Add($Automatic)
$Manual = New-Object System.Windows.Forms.Button
$Manual.Location = New-Object System.Drawing.Size(270,80)
$Manual.Size = New-Object System.Drawing.Size(100,30)
$Manual.Text = "Manually"
$Manual.Font = 'Microsoft Sans Serif,10'
$Manual.BackColor = "#e47104"
$Manual.Add_Click($Manual_Button)
$MainForm.Controls.Add($Manual)
$MainForm.ShowDialog()
Use a global variable for storing a result.
$Auto_Button = ({ $global:result=10
$MainForm.Close() })
$Manual_Button = ({ $global:result=20
$MainForm.Close() })
...
$result=0
$MainForm.ShowDialog()
$result | Out-File .\exit.txt
exit $result