title: Build Checkbox list programmatically using powershell
body: <p>I am trying to populate checkbox from value return in   <code>$domain = Get-MsolDomain</code> which return domains available then generate the checkbox based on the value return and excluding the value from @mail. Thank you</p>
  
  <p>Here is the code that i have so far:</p>
  
  <pre><code>$snapin = Get-PSSnapin | Where-Object {$_.Name -eq 'Microsoft.SharePoint.Powershell'} 
  if ($snapin -eq $null) 
  {
      Write-Host -foregroundcolor Green "Loading SharePoint PowerShell Snapin"
      Add-PSSnapin "Microsoft.SharePoint.Powershell"
  }
  Import-Module MSOnline
  $credentials = Get-Credential
  Connect-MsolService -Credential $credentials
  
  $unlicensedUsersBatch500 = Get-MsolUser -UnlicensedUsersOnly -MaxResults 500
  
  
  
  [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,700) 
  $Form.text ="Office 365 Licence Activation" 
  
  ############################################## Start group boxes
  
  $groupBox = New-Object System.Windows.Forms.GroupBox
  $groupBox.Location = New-Object System.Drawing.Size(240,20) 
  $groupBox.size = New-Object System.Drawing.Size(200,100) 
  $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
  
  
  
  foreach ($a in $domain)
  {    
  
      for ($i=1;$i -lt 6; $i++) 
      {
      $Checkboxes.Text = $a.Name
      }
  }
  $groupBox.Controls.Add($Checkboxes) 
  </code></pre>