mrfite
asked on
Stop Powershell Script if the user 'X'.s out of the script
Good Day,
I am looking to the experts to help in what should be a minor issue.
The following is a script I created and it works perfectly exect if the user 'X' out of the gui then it still generates an email without information added to it.
I am looking to the experts to help in what should be a minor issue.
The following is a script I created and it works perfectly exect if the user 'X' out of the gui then it still generates an email without information added to it.
# help with layout from https://poshgui.com/#
Add-Type -AssemblyName System.Windows.Forms
$Dexis = New-Object system.Windows.Forms.Form
$Dexis.Text = "Dexis Error Reporting Tool"
$Dexis.TopMost = $true
$Dexis.Width = 635
$Dexis.Height = 402
$Patient = New-Object system.windows.Forms.Label
$Patient.Text = "Please provide the patient identifier that you put into dexis"
$Patient.AutoSize = $true
$Patient.Width = 25
$Patient.Height = 10
$Patient.location = new-object system.drawing.point(9,48)
$Patient.Font = "Microsoft Sans Serif,10"
$Dexis.controls.Add($Patient)
$textBox3 = New-Object system.windows.Forms.TextBox
$textBox3.Width = 224
$textBox3.Height = 20
$textBox3.location = new-object system.drawing.point(379,47)
$textBox3.Font = "Microsoft Sans Serif,12"
$Dexis.controls.Add($textBox3)
$checkBox4 = New-Object system.windows.Forms.CheckBox
$checkBox4.Text = " Dexis Button Issue"
$checkBox4.AutoSize = $true
$checkBox4.Width = 95
$checkBox4.Height = 20
$checkBox4.location = new-object system.drawing.point(406,83)
$checkBox4.Font = "Microsoft Sans Serif,10"
$Dexis.controls.Add($checkBox4)
$label5 = New-Object system.windows.Forms.Label
$label5.Text = "Check box if this is an issue with the Dexis Button in NextGen"
$label5.AutoSize = $true
$label5.Width = 25
$label5.Height = 10
$label5.location = new-object system.drawing.point(10,82)
$label5.Font = "Microsoft Sans Serif,10"
$Dexis.controls.Add($label5)
$textBox6 = New-Object system.windows.Forms.TextBox
$textBox6.Multiline = $true
$textBox6.Width = 559
$textBox6.Height = 116
$textBox6.location = new-object system.drawing.point(11,157)
$textBox6.Font = "Microsoft Sans Serif,10"
$Dexis.controls.Add($textBox6)
$label8 = New-Object system.windows.Forms.Label
$label8.Text = "Additional Information:"
$label8.AutoSize = $true
$label8.Width = 25
$label8.Height = 10
$label8.location = new-object system.drawing.point(11,134)
$label8.Font = "Microsoft Sans Serif,10"
$Dexis.controls.Add($label8)
$button9 = New-Object system.windows.Forms.Button
$button9.Text = "Ok"
$button9.Width = 60
$button9.Height = 30
$button9.location = new-object system.drawing.point(514,302)
$button9.Font = "Microsoft Sans Serif,10"
$button9.Add_Click({$Dexis.Close()})
$Dexis.controls.Add($button9)
$button10 = New-Object system.windows.Forms.Button
$button10.Text = "Cancel"
$button10.Width = 60
$button10.Height = 30
$button10.location = new-object system.drawing.point(414,302)
$button10.Font = "Microsoft Sans Serif,10"
$button10.Add_Click({[System.Environment]::Exit(0)})
$Dexis.controls.Add($button10)
#if cancel, stop script
#[void] $Dexis.ShowDialog()
#if ($cancel) {$Dexis.Dispose()}
[void]$Dexis.ShowDialog()
$Dexis.Dispose()
$ol = New-Object -comObject Outlook.Application
$newmail = $ol.CreateItem(0)
$newmail.Recipients.Add('me@email.net') | Out-Null
$newmail.Subject = "Dexis Malfunction reported on " + $env:COMPUTERNAME
$newmail.HTMLBody = "
<br>Time: $(Get-date)
<br>
<br>System: $($env:COMPUTERNAME).$($env:USERDNSDOMAIN)
<br>
<br>Reporting user: $($env:username)
<br>
<br>Issue with Dexis:
<br>
"
IF ($checkbox4.Checked -eq 'y'){$newmail.HTMLBody = $newmail.HTMLBody + "<br>The user reports an issue with the Dexis Button in NextGen not working.
<br>"}
$newmail.HTMLBody = $newmail.HTMLBody + "
<br>Patent Affected by this issue: $($textbox3.text)
<br>
<br>Additional Comments: $($textbox6.text)
<br>
"
$newmail.Save()
$inspector = $newmail.GetInspector
$inspector.Display()
Your assistance is appreciated and most welcome.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.