I am writing the script which have two forms first form is Form1 which has 3 radio buttons , 1 multi ListBox and second is Form2. What I am trying to achieve that , after selecting desired options and items in listbox it should show form2 with all selection values from Form1 to confirm if all selected values are correct. After getting confirmation selected values should be used in form1 to process something and pass that to another xyz function.
Issue is after getting confirmation from form2 , form1 dont show the selected value as output in $confirmation variable if i want to use that values for further processing. but it shows If I write write-host $confirmation. Not sure what I need to do it here. Please help.
Below is the Form1 Procced button code
## btn_Proceed
$btn_Proceed.Location = New-Object System.Drawing.Point(392, 522)
$btn_Proceed.Name = "btn_Proceed"
$btn_Proceed.Size = New-Object System.Drawing.Size(75, 23)
$btn_Proceed.TabIndex = 11
$btn_Proceed.Text = "Proceed"
$btn_Proceed.UseVisualStyleBackColor = $true
$btn_Proceed.Add_click({
if($rad_azure.Checked){
$cloud = "Azure"
}
if($rad_aws.Checked){
$cloud = "AWS"
}
if($rad_usa.Checked){
$region = "USA"
}
if($rad_emea.Checked){
$region = "EMEA"
}
if($rad_apac.Checked){
$region = "APAC"
}
if($rad_cio.Checked){
$environment = "CIO Cloud"
}
if($rad_legacy.Checked){
$environment = "Legacy Cloud"
}
if($rad_wave1.Checked){
$wave = "Wave1"
}
if($rad_wave2.Checked){
$wave = "Wave2"
}
if($rad_wave3.Checked){
$wave = "Wave3"
}
if($rad_prepatching.Checked){
$patchingstage = "Pre-Patching"
}
if($rad_postpatching.Checked){
$patchingstage = "Post-Patching"
}
$clients = $lb_available.Items
$Confirmseletion = form-confirmation -region $region -cloud $cloud -environment $environment -wave $wave -patchingstage $patchingstage -clients $clients
$Confirmseletion
$frm_patching.Close()
})
#Below is the Form2 function script
function form-confirmation {
param($region, $cloud, $environemnt, $wave, $patchingstage, $clients)
Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.Drawing
$frm_confirm = New-Object System.Windows.Forms.Form
$txtb_cloud = New-Object System.Windows.Forms.TextBox
$txtb_env = New-Object System.Windows.Forms.TextBox
$txtb_region = New-Object System.Windows.Forms.TextBox
$label1 = New-Object System.Windows.Forms.Label
$label2 = New-Object System.Windows.Forms.Label
$label3 = New-Object System.Windows.Forms.Label
$label4 = New-Object System.Windows.Forms.Label
$label5 = New-Object System.Windows.Forms.Label
$label6 = New-Object System.Windows.Forms.Label
$txtb_wave = New-Object System.Windows.Forms.TextBox
$txtxb_patching = New-Object System.Windows.Forms.TextBox
$txtb_clients = New-Object System.Windows.Forms.TextBox
$btn_confirm = New-Object System.Windows.Forms.Button
$btn_cancel = New-Object System.Windows.Forms.Button
#
# txtb_cloud
#
$txtb_cloud.Location = New-Object System.Drawing.Point(123, 29)
$txtb_cloud.ReadOnly = $true
$txtb_cloud.Name = "txtb_cloud"
$txtb_cloud.Size = New-Object System.Drawing.Size(135, 20)
$txtb_cloud.Text = $cloud
$txtb_cloud.TabIndex = 0
#
# txtb_env
#
$txtb_env.Location = New-Object System.Drawing.Point(123, 61)
$txtb_env.ReadOnly = $true
$txtb_env.Name = "txtb_env"
$txtb_env.Size = New-Object System.Drawing.Size(135, 20)
$txtb_env.Text = $environemnt
$txtb_env.TabIndex = 1
#
# txtb_region
#
$txtb_region.Location = New-Object System.Drawing.Point(123, 94)
$txtb_region.ReadOnly = $true
$txtb_region.Name = "txtb_region"
$txtb_region.Size = New-Object System.Drawing.Size(135, 20)
$txtb_region.Text = $region
$txtb_region.TabIndex = 2
#
# label1
#
$label1.AutoSize = $true
$label1.Location = New-Object System.Drawing.Point(76, 29)
$label1.Name = "label1"
$label1.Size = New-Object System.Drawing.Size(34, 13)
$label1.TabIndex = 3
$label1.Text = "Cloud"
#
# label2
#
$label2.AutoSize = $true
$label2.Location = New-Object System.Drawing.Point(44, 61)
$label2.Name = "label2"
$label2.Size = New-Object System.Drawing.Size(66, 13)
$label2.TabIndex = 4
$label2.Text = "Environemnt"
#
# label3
#
$label3.AutoSize = $true
$label3.Location = New-Object System.Drawing.Point(69, 94)
$label3.Name = "label3"
$label3.Size = New-Object System.Drawing.Size(41, 13)
$label3.TabIndex = 5
$label3.Text = "Region"
#
# label4
#
$label4.AutoSize = $true
$label4.Location = New-Object System.Drawing.Point(29, 129)
$label4.Name = "label4"
$label4.Size = New-Object System.Drawing.Size(81, 13)
$label4.TabIndex = 6
$label4.Text = "Patching Wave"
#
# label5
#
$label5.AutoSize = $true
$label5.Location = New-Object System.Drawing.Point(6, 171)
$label5.Name = "label5"
$label5.Size = New-Object System.Drawing.Size(104, 13)
$label5.TabIndex = 7
$label5.Text = "Pre or Post Patching"
#
# label6
#
$label6.AutoSize = $true
$label6.Location = New-Object System.Drawing.Point(318, 29)
$label6.Name = "label6"
$label6.Size = New-Object System.Drawing.Size(38, 13)
$label6.TabIndex = 8
$label6.Text = "Clients"
#
# txtb_wave
#
$txtb_wave.Location = New-Object System.Drawing.Point(123, 129)
$txtb_wave.ReadOnly = $true
$txtb_wave.Name = "txtb_wave"
$txtb_wave.Size = New-Object System.Drawing.Size(135, 20)
$txtb_wave.Text = $wave
$txtb_wave.TabIndex = 9
#
# txtxb_patching
#
$txtxb_patching.Location = New-Object System.Drawing.Point(122, 164)
$txtxb_patching.ReadOnly = $true
$txtxb_patching.Name = "txtxb_patching"
$txtxb_patching.Size = New-Object System.Drawing.Size(135, 20)
$txtxb_patching.Text = $patchingstage
$txtxb_patching.TabIndex = 10
#
# txtb_clients
#
$txtb_clients.Location = New-Object System.Drawing.Point(321, 52)
$txtb_clients.ReadOnly =$true
$txtb_clients.Multiline = $true
$txtb_clients.Name = "txtb_clients"
$txtb_clients.Size = New-Object System.Drawing.Size(223, 132)
for($i=0; $i -lt $clients.Count; $i++){
if(($i + 1) -lt $clients.count){
$txtb_clients.Text += $clients[$i]
$txtb_clients.AppendText("`r`n")
}
else{
$txtb_clients.Text += $clients[$i]
}
}
$txtb_clients.TabIndex = 11
#
# btn_confirm
#
$btn_confirm.Location = New-Object System.Drawing.Point(183, 212)
$btn_confirm.Name = "btn_confirm"
$btn_confirm.Size = New-Object System.Drawing.Size(75, 23)
$btn_confirm.TabIndex = 12
$btn_confirm.Text = "Confirm"
$btn_confirm.UseVisualStyleBackColor = $true
$btn_confirm.add_click({
$frm_confirm.DialogResult = [System.Windows.Forms.DialogResult]::OK
$frm_confirm.Close()
})
#
# btn_cancel
#
$btn_cancel.Location = New-Object System.Drawing.Point(321, 212)
$btn_cancel.Name = "btn_cancel"
$btn_cancel.Size = New-Object System.Drawing.Size(75, 23)
$btn_cancel.TabIndex = 13
$btn_cancel.Text = "Cancel"
$btn_cancel.UseVisualStyleBackColor = $true
$frm_confirm.CancelButton = $btn_cancel
#
# frm_confirm
#
$frm_confirm.ClientSize = New-Object System.Drawing.Size(578, 279)
$frm_confirm.Controls.Add($btn_cancel)
$frm_confirm.Controls.Add($btn_confirm)
$frm_confirm.Controls.Add($txtb_clients)
$frm_confirm.Controls.Add($txtxb_patching)
$frm_confirm.Controls.Add($txtb_wave)
$frm_confirm.Controls.Add($label6)
$frm_confirm.Controls.Add($label5)
$frm_confirm.Controls.Add($label4)
$frm_confirm.Controls.Add($label3)
$frm_confirm.Controls.Add($label2)
$frm_confirm.Controls.Add($label1)
$frm_confirm.Controls.Add($txtb_region)
$frm_confirm.Controls.Add($txtb_env)
$frm_confirm.Controls.Add($txtb_cloud)
$frm_confirm.Name = "frm_confirm"
$frm_confirm.Text = "Confirm Selection"
$frm_confirm.TopMost = $true
#$frm_confirm.ShowDialog()
#$frm_confirm.DialogResult.ToString()
if($frm_confirm.ShowDialog() -eq [System.Windows.Forms.DialogResult]::OK){
$inputparam = @{
'availableAccounts' = $txtb_clients.Text
'Patchingstage' = $txtxb_patching.Text
'patchingwave' = $txtb_wave.Text
'patchingregion' = $txtb_region.Text
'patchingenvironemnt' = $txtb_env.Text
'patchingcloud' = $txtb_cloud.Text
}
}
return $inputparam
}