dimanche 25 septembre 2016

How Do I Access CheckBoxes From a Function

I've created a form and dynamically added CheckBoxes and CheckBox names. How can I programmatically check one particular CheckBox from the Get-LicenseDetails function? Thanks. Hi, I've created a form and dynamically added CheckBoxes and CheckBox names. How can I programmatically check one particular CheckBox from the Get-LicenseDetails function? Thanks.

import-module MSOnline

Function Get-LicenseDetails {
    Param ($upn)
    $licenses = Get-MsolUser -UserPrincipalName $upn
    ForEach ($license in $licenses.Licenses) {
        If ($license.AccountSkuId -like '*ENTERPRISEPACK') {
            $serviceName = $serviceStatus.ServicePlan.ServiceName
            $checkBox.Checked = $true
        }
    }
}

[void] System.Reflection.Assembly]::LoadWithPartialName("System.Drawing") 
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") 

$System_Drawing_Point = New-Object System.Drawing.Point
Add-Type -AssemblyName System.Windows.Forms
$form = New-Object Windows.Forms.Form
$form.Text = "Office 365 Licensing"
$form.Name = "Form1"
$form.Size = New-Object Drawing.Size @(316, 510)

#SEARCH BUTTON
$searchBtn = New-Object System.Windows.Forms.Button
$System_Drawing_Point.X = 226 
$System_Drawing_Point.Y = 38 
$searchBtn.Location = $System_Drawing_Point 
$searchBtn.add_click({Get-LicenseDetails "user.name@domain.com"})
$searchBtn.Size = New-Object System.Drawing.Size(67, 23)
$searchBtn.Text = "Click Me"
$form.Controls.Add($searchBtn)

#CHECKBOXES
$y = 80
$Services = (Get-MsolAccountSku | Where-Object {$_.SkuPartNumber -eq "ENTERPRISEPACK"}).ServiceStatus.ServicePlan.ServiceName
ForEach ($service in $Services) {
    $checkbox = New-Object System.Windows.Forms.CheckBox
    $checkbox.Text = $service
    $checkbox.Name = "CheckBox_$service"
    $checkbox.Size = New-Object System.Drawing.Size(260,17)
    $checkbox.Location = New-Object System.Drawing.Size(10,$y) 
    $y += 25
    $form.Controls.Add($checkbox) 
}

$drc = $form.ShowDialog()




Aucun commentaire:

Enregistrer un commentaire