I am very new to PowerShell and have two scripts that are interacting with one another. The first script is a GUI that asks users for several inputs, and then stores them as variables. Two types of variables are text and list selections. I am then using the 2nd script to run the 1st, and then send an email.
I am not able to get just the text or selected value of my user inputs. One of the text boxes is below:
I’m just trying to make a lot of repetitive emails we send out easier for my team. Any help is appreciated!
Inputs in the GUI script are as follows:
$ticketNumber = New-Object System.Windows.Forms.TextBox
$ticketNumber.Location = New-Object System.Drawing.Point(10,30)
$ticketNumber.Size = New-Object System.Drawing.Size(260,20)
$form.Controls.Add($ticketNumber)
$equipment = New-Object System.Windows.Forms.ListBox
$equipment.Location = New-Object System.Drawing.Point(10,80)
$equipment.Size = New-Object System.Drawing.Size(260,20)
$equipment.Height = 60
[void] $equipment.Items.Add('Laptop, dock, monitor')
[void] $equipment.Items.Add('Laptop, dock, monitor, 2nd monitor')
[void] $equipment.Items.Add('Desktop, monitor')
[void] $equipment.Items.Add('2nd monitor')
$form.Controls.Add($equipment)
Then the 2nd script looks like this:
. "$PSScriptRootTestInput.ps1"
$Outlook = New-Object -ComObject Outlook.Application
$Mail = $Outlook.CreateItem(0)
$Mail.Sender = $Outlook.GetNamespace("MAPI").Accounts.Item(1).SmtpAddress # or '[email protected]'
$Mail.To = $Outlook.GetNamespace("MAPI").Accounts.Item(1).SmtpAddress
$Mail.Subject = "Equipment to add"
$Mail.Body = "Ticket: $TestInput.$ticketNumber"
$Mail.Body = "Ticket: $tTestInput.$equipment"
The Email output is this:
Ticket: System.Windows.Forms.TextBox, Text: RITM
Requested: .System.Windows.Forms.ListBox, Items.Count: 4, Items[0]: Laptop, dock, monitor
How do I get just the selected value or the text?
Elliot C. J. McBride is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.