0

I am trying to populate checkbox from value return in $domain = Get-MsolDomain which return domains available then generate the checkbox based on the value return and excluding the value from @mail. Thank you

Here is the code that i have so far:

$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) 

1 Answer 1

2

I would do it as follows. Note that I created and populated $domain for the sake of testing, so you will need to replace that with your call to Get-MsolDomain. Small plus, the size of the groupbox will grow automatically, based on the number of elements in $domain.

[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.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
    $groupBox.Controls.Add($Checkbox) 
    $Checkboxes += $Checkbox
}
$groupBox.size = New-Object System.Drawing.Size(200,(40*$checkboxes.Count)) 
$form.ShowDialog()| Out-Null
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.