Richard Gardner
asked on
Powershell Form - join checkbox outputs to single string separated by comma
I am building a Form from Powershell with a dynamically created checkbox list (populated by Office 365). I have a function which outputs the checkbox outputs to a single string separated by comma.
I can achieve this by adding a comma to the end of each output but I do not want the final output to have a comma at the end.
Current output = domain1,domain2,domain3, (note the unwanted , on the end)
Expected output = domain1,domain2,domain3
I have the code written below using some static checkbox outputs. Line 58 is where the join happens.
I can achieve this by adding a comma to the end of each output but I do not want the final output to have a comma at the end.
Current output = domain1,domain2,domain3, (note the unwanted , on the end)
Expected output = domain1,domain2,domain3
I have the code written below using some static checkbox outputs. Line 58 is where the join happens.
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing")
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
$Form = New-Object System.Windows.Forms.Form
$Form.Size = New-Object System.Drawing.Size(600,600)
$Form.text ="Office 365"
#Start group boxes
$groupBox = New-Object System.Windows.Forms.GroupBox
$groupBox.Location = New-Object System.Drawing.Size(10,20)
$groupBox.text = "Availabe Office 365 Domains:"
$Form.Controls.Add($groupBox)
$Checkboxes += New-Object System.Windows.Forms.CheckBox
$Checkboxes.Location = New-Object System.Drawing.Size(10,20)
#$domain = Get-MsolDomain
$domain = @()
$domain += @{"Name"="domain1"}
$domain += @{"Name"="domain2"}
$domain += @{"Name"="domain3"}
$Checkboxes = @()
$y = 20
foreach ($a in $domain)
{
$Checkbox = New-Object System.Windows.Forms.CheckBox
$Checkbox.Text = $a.Name
$Checkbox.Location = New-Object System.Drawing.Size(10,$y)
$y += 30
$Checkbox.Width = 300
$groupBox.Controls.Add($Checkbox)
$Checkboxes += $Checkbox
}
$groupBox.size = New-Object System.Drawing.Size(570,(40*$checkboxes.Count))
#OUTPUTBOX
$Button2 = New-Object System.Windows.Forms.Button
$Button2.Location = New-Object System.Drawing.Size(20,200)
$Button2.Size = New-Object System.Drawing.Size(70,30)
$Button2.Text = "Output"
$Button2.Add_Click({funcOutputBox})
$Form.Controls.Add($Button2)
$OutputBox = New-Object System.Windows.Forms.TextBox
$OutputBox.Location = New-Object System.Drawing.Size(20,260)
$OutputBox.Size = New-Object System.Drawing.Size(530,50)
$OutputBox.MultiLine = $True
$OutputBox.ScrollBars = "Vertical"
$Form.Controls.Add($OutputBox)
function funcOutputBox {
Foreach ($o in $Checkboxes) {if (!$o.Checked) {$CheckboxesString += $o.Text + ","}}
$OutputBox.text = "$CheckboxesString"
}
$form.ShowDialog()| Out-Null
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER